node.js - 使用 Angular-Meteor 运行预定作业的最理想方式

标签 node.js mongodb angular meteor angular-meteor

我正在使用 angular-meteor 编写一个约会安排应用程序。其中一项要求是向预约的客户发送短信通知。客户提供手机号码。但基本上,我想做的就是在预约时间前 X 分钟发送一封电子邮件。运行 Angular meteor 堆栈,最好的方法是什么?所有预约信息都保存到 mongo 数据库中。

最佳答案

您可能对 Meteor job-collection 感兴趣包(不特定于 angle-meteor):

A persistent and reactive job queue for Meteor, supporting distributed workers that can run anywhere.

job-collection is a powerful and easy to use job manager designed and built for Meteor.js.

It solves the following problems (and more):

  • Schedule jobs to run (and repeat) in the future, persisting across server restarts
  • […]

特别是job.after(someTimeBeforeAppointment)

// Server
var myJobs = JobCollection('myJobQueue');

// Start the myJobs queue running
myJobs.startJobServer();


// Create a Job (e.g. in a Meteor method)
var job = new Job(myJobs, 'jobType', jobData);

// Specify when it can run and save it.
job.after(someTimeBeforeAppointment).save();


// Server (or could be a different server!)
// How jobs should be processed.
myJobs.processJobs('jobType', function (job, done) {
    var jobData = job.data;

    // Do something… could be asynchronous.
    job.done(); // or job.fail();

    // Call done when work on this job has finished.
    done();
});

可以在 processJobs options 中指定 pollInterval 。默认为每 5 秒一次。

关于node.js - 使用 Angular-Meteor 运行预定作业的最理想方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43481842/

相关文章:

node.js - 在 arm-linux 上安装 node-serialport 模块

javascript - 在nodejs中使用fs的绝对路径

javascript - nodejs for 循环,调用异步 Mongo 函数 - 但 Mongo 函数仅针对最后一项调用 X 次

javascript - Angular HttpInterceptor : How to use RxJS for multiple conditions

typescript - 使用 Angular 2 连接 Google Maps Nativescript 插件

javascript - 您将如何实现类似于 React Native 的条件导入?

json - 将表单类型更改为 multipart/form-data 会导致 req.body 为空

mongodb - Golang 从 MongoDB 的嵌套 json 数据映射中找到一个值

javascript - 了解 node.js 异步性 - for 循环与嵌套回调

android - 元素使用权限#android.permission.CAMERA 与在 AndroidManifest.xml 中声明的元素重复