[英]Background tasks in Meteor
I'm wondering, is there is way to implement background taks, maybe with workers pool. 我想知道,是否有办法实施背景技术,也许有工人池。 Can you show me direction, i'm thinking about writing package for this? 你能告诉我方向吗,我正在考虑为此编写包装?
Before thinking about writing a package for anything, first look if there are existing packages that do what you need. 在考虑为任何东西编写包之前,首先看一下现有的包是否能满足您的需求。 In the Meteor world, this means looking on Atmosphere for "job/queue/task/worker management/scheduling" packages, then on npm for the same search terms. 在Meteor世界中,这意味着在Atmosphere上查找“作业/队列/任务/工作人员管理/日程安排”软件包,然后在npm上查找相同的搜索条件。 You also need to define your requirements more precisely: 您还需要更精确地定义您的要求:
Abandoned packages: 被遗弃的包裹:
Meteor has been able to use npm packages directly for several years now, so this question amounts to finding job/worker/queue management packages on NPM. Meteor已经能够直接使用npm包几年了,所以这个问题相当于在NPM上找到作业/工作人员/队列管理包 。 If you don't care about persistence: 如果你不关心持久性:
map
, reduce
, filter
, each
...) as well as some common patterns for asynchronous control flow ( parallel
, series
, waterfall
...)" Async “提供了大约70个函数,包括通常的'功能'嫌疑( map
, reduce
, filter
, each
......)以及异步控制流的一些常见模式( parallel
, series
, waterfall
...)” If you do want persistence, since Meteor uses MongoDB already, it may be advantageous to use a job scheduling package with persistence to MongoDb. 如果你确实需要持久性,因为Meteor已经使用了MongoDB,所以使用具有持久性的作业调度包对MongoDb可能是有利的。 The most powerful and popular seems to be Agenda , but unfortunately it hasn't been maintained in months, and it has a significant backlog of issues . 最强大和最受欢迎的似乎是议程 ,但不幸的是它几个月没有得到维护,并且它有大量积压的问题 。
If you're willing to add a dependency backed by redis to your project, there are more choices: 如果您愿意将redis支持的依赖项添加到项目中,还有更多选择:
Like MongoDB, Redis can also provide high-availability (via Redis Sentinel), and if you want to distribute jobs among multiple worker machines, you can point them all at the same Redis server . 与MongoDB一样,Redis也可以提供高可用性(通过Redis Sentinel),如果要在多个工作机器之间分配作业,可以将它们全部指向同一个Redis服务器 。
There is a package based on Cron jobs which can be used to schedule tasks on certain intervals or dates. 有一个基于Cron作业的包,可用于在某些时间间隔或日期安排任务。 Here is the package: https://atmosphere.meteor.com/package/cron 这是一个包: https : //atmosphere.meteor.com/package/cron
And if you happen to look into the source of that package, you'll notice they're simply using: 如果您碰巧查看该软件包的来源,您会发现他们只是使用:
Meteor.setInterval( ... , delay );
So if you save your tasks in a database, then load them into intervals during startup, then you'll probably be on the right track. 因此,如果您将任务保存在数据库中,然后在启动期间将它们加载到间隔中,那么您可能会走上正确的轨道。
If you are looking for something that is specific to Meteor, I am happy to share there is a new package called Steve Jobs. 如果您正在寻找Meteor特有的东西,我很高兴地分享一个名为Steve Jobs的新软件包。 It makes running background jobs as easy as calling a Method. 它使运行后台作业与调用Method一样简单。
It has all the standard features you would expect, such as running a job only once, retrying failed jobs, and so on. 它具有您期望的所有标准功能,例如仅运行一次作业,重试失败的作业等。 You can learn more about it on GitHub: 您可以在GitHub上了解更多相关信息:
http://github.com/msavin/stevejobs http://github.com/msavin/stevejobs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.