简体   繁体   English

流星的背景任务

[英]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? 你能告诉我方向吗,我正在考虑为此编写包装?

2019 update 2019年更新

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: 您还需要更精确地定义您的要求:

  • do you want persistence, or would an in-memory solution work? 你想要持久性,还是内存解决方案有效?
  • do you want to be able to distribute jobs to different machines? 您希望能够将作业分发到不同的机器吗?

Meteor-specific 流星专用

  • job-collection - reliable (I used it in 2014 in production at a startup), but currently in maintenance mode. 工作收集 - 可靠(我在2014年在初创公司的生产中使用它),但目前处于维护模式。 Lets you schedule persistent jobs to be run anywhere (servers, clients). 允许您安排在任何地方运行的持久性作业(服务器,客户端)。
  • SteveJobs - actively maintained by Max Savin, the author of several powerful Meteor tools SteveJobs - 由几个强大的Meteor工具的作者Max Savin积极维护
  • littledata:synced-cron - "A simple cron system for Meteor. It supports syncronizing jobs between multiple processes." littledata:synced-cron - “Meteor的一个简单的cron系统。它支持在多个进程之间同步作业。”

Abandoned packages: 被遗弃的包裹:

Npm packages Npm包

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: 如果你不关心持久性:

  • Async "provides around 70 functions that include the usual 'functional' suspects ( map , reduce , filter , each ...) as well as some common patterns for asynchronous control flow ( parallel , series , waterfall ...)" Async “提供了大约70个函数,包括通常的'功能'嫌疑( mapreducefiltereach ......)以及异步控制流的一些常见模式( parallelserieswaterfall ...)”
  • d3-queue - minimalistic, written by D3 author Mike Bostock d3-queue - minimalistic,由D3作家Mike Bostock编写

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

I'm guessing proper support is on their roadmap, but in the meantime I've managed to get it going in a hacky way via setInterval . 我猜他们的路线图上有适当的支持,但与此同时我已经设法通过setInterval以一种hacky方式进行。 See the cron-tick package. 请参阅cron-tick包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM