Introduction

rethinkdb-job-queue is a persistent job or task queue backed by RethinkDB. It has been built as an alternative to the many queues available on NPM.

bitHound Overall Score bitHound Dependencies bitHound Dependencies js-standard-style NSP Status

Thinker

NPM

Please Star on GitHub / NPM and Watch for updates.

Features

Documentation

Quick Start

Installation

Note: You will need to install RethinkDB before you can use rethinkdb-job-queue.

npm install rethinkdb-job-queue --save

See the installation document for supported Node.js versions and workarounds.

Simple Example

const Queue = require('rethinkdb-job-queue')
const qOptions = {
  name: 'Mathematics' // The queue and table name
}
const cxnOptions = {
  db: 'JobQueue', // The name of the database in RethinkDB
}

const q = new Queue(cxnOptions, qOptions)

const job = q.createJob({
  numerator: 123,
  denominator: 456
})

q.process((job, next) => {
    try {
      let result = job.numerator / job.denominator
      // Do something with your result
      return next(null, result)
    } catch (err) {
      console.error(err)
      return next(err)
    }
})

return q.addJob(job).catch((err) => {
  console.error(err)
})

E-Mail Job Example using nodemailer

// The following is not related to rethinkdb-job-queue.
// This is the nodemailer configuration
const nodemailer = require('nodemailer')
const transporter = nodemailer.createTransport({
  service: 'Mailgun',
  auth: {
    user: 'postmaster@superheros.com',
    pass: 'your-api-key-here'
  }
})

// Setup e-mail data with unicode symbols
var mailOptions = {
  from: '"Registration" <support@superheros.com>', // Sender address
  subject: 'Registration', // Subject line
  text: 'Click here to complete your registration', // Plaintext body
  html: '<b>Click here to complete your registration</b>' // HTML body
}

// rethinkdb-job-queue configuration
const Queue = require('rethinkdb-job-queue')

// Queue options have defaults and are not required
const qOptions = {
  name: 'RegistrationEmail', // The queue and table name
  masterInterval: 310000, // Database review period in milliseconds
  changeFeed: true, // Enables events from the database table
  concurrency: 100,
  removeFinishedJobs: 2592000000, // true, false, or number of milliseconds
}

// Connection options have defaults and are not required
// You can replace these options with a rethinkdbdash driver object
const cxnOptions = {
  host: 'localhost',
  port: 28015,
  db: 'JobQueue', // The name of the database in RethinkDB
}

// This is the main queue instantiation call
const q = new Queue(cxnOptions, qOptions)

// Customizing the default job options for new jobs
q.jobOptions = {
  priority: 'normal',
  timeout: 300000,
  retryMax: 3, // Four attempts, first then three retries
  retryDelay: 600000 // Time in milliseconds to delay retries
}

const job = q.createJob()
// The createJob method will only create the job locally.
// It will need to be added to the queue.
// You can decorate the job with any data to be saved for processing
job.recipient = 'batman@batcave.com'

q.process((job, next) => {
  // Send email using job.recipient as the destination address
  mailOptions.to = job.recipient
  return transporter.sendMail(mailOptions).then((info) => {
    console.dir(info)
    return next(null, info)
  }).catch((err) => {
    // This catch is for nodemailer sendMail errors.
    return next(err)
  })
})

return q.addJob(job).then((savedJobs) => {
  // savedJobs is an array of the jobs added with updated properties
}).catch((err) => {
  console.error(err)
})

About the Owner

I, Grant Carthew, am a technologist, trainer, and Dad from Queensland, Australia. I work on code in a number of personal projects and when the need arises I build my own packages.

This project exists because there were no functional job queues built on the RethinkDB database. I wanted an alternative to the other job queues on NPM.

Everything I do in open source is done in my own time and as a contribution to the open source community.

See my other projects on NPM.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Please see the debugging and testing documents for more detail.

Credits

Thanks to the following marvelous packages and people for their hard work:

This list could go on...

License

MIT



Introduction

rethinkdb-job-queue 是由 RethinkDB 支持的持久性作业或任务队列。 它已经构建为 NPM 上可用的许多队列的替代方案。

bitHound总体得分data-canonical-src bitHound相关性 bitHound JS-标准式 NSP状态data-canonical-src

思想者data-canonical-src

NPM

请在GitHub / NPM上星标观看进行更新。

功能

文件

快速入门

安装

注意:您需要安装 RethinkDB ,然后才能使用 rethinkdb-job-队列

npm install rethinkdb-job-queue –save

有关支持的Node.js版本和解决方法,请参见安装文档。 p>

简单例子

const Queue = require('rethinkdb-job-queue')
const qOptions = {
  name: 'Mathematics' // The queue and table name
}
const cxnOptions = {
  db: 'JobQueue', // The name of the database in RethinkDB
}

const q = new Queue(cxnOptions, qOptions)

const job = q.createJob({ numerator: 123, denominator: 456 })

q.process((job, next) => { try { let result = job.numerator / job.denominator // Do something with your result return next(null, result) } catch (err) { console.error(err) return next(err) } })

return q.addJob(job).catch((err) => { console.error(err) })

使用 nodemailer 的电子邮件作业示例

// The following is not related to rethinkdb-job-queue.
// This is the nodemailer configuration
const nodemailer = require('nodemailer')
const transporter = nodemailer.createTransport({
  service: 'Mailgun',
  auth: {
    user: 'postmaster@superheros.com',
    pass: 'your-api-key-here'
  }
})

// Setup e-mail data with unicode symbols var mailOptions = { from: '"Registration" <support@superheros.com>', // Sender address subject: 'Registration', // Subject line text: 'Click here to complete your registration', // Plaintext body html: '<b>Click here to complete your registration</b>' // HTML body }

// rethinkdb-job-queue configuration const Queue = require('rethinkdb-job-queue')

// Queue options have defaults and are not required const qOptions = { name: 'RegistrationEmail', // The queue and table name masterInterval: 310000, // Database review period in milliseconds changeFeed: true, // Enables events from the database table concurrency: 100, removeFinishedJobs: 2592000000, // true, false, or number of milliseconds }

// Connection options have defaults and are not required // You can replace these options with a rethinkdbdash driver object const cxnOptions = { host: 'localhost', port: 28015, db: 'JobQueue', // The name of the database in RethinkDB }

// This is the main queue instantiation call const q = new Queue(cxnOptions, qOptions)

// Customizing the default job options for new jobs q.jobOptions = { priority: 'normal', timeout: 300000, retryMax: 3, // Four attempts, first then three retries retryDelay: 600000 // Time in milliseconds to delay retries }

const job = q.createJob() // The createJob method will only create the job locally. // It will need to be added to the queue. // You can decorate the job with any data to be saved for processing job.recipient = 'batman@batcave.com'

q.process((job, next) => { // Send email using job.recipient as the destination address mailOptions.to = job.recipient return transporter.sendMail(mailOptions).then((info) => { console.dir(info) return next(null, info) }).catch((err) => { // This catch is for nodemailer sendMail errors. return next(err) }) })

return q.addJob(job).then((savedJobs) => { // savedJobs is an array of the jobs added with updated properties }).catch((err) => { console.error(err) })

关于业主

我是Grant Carthew,是澳大利亚昆士兰州的技术专家,培训师和爸爸。我在一些个人项目中编写代码,当需要时,我建立自己的包。

此项目存在,因为在RethinkDB数据库上没有构建功能的作业队列。我想要一个备用NPM的其他作业队列。

我在开放源代码中做的一切都是在我自己的时间完成的,也是对开源社区的贡献

请参阅我的 NPM上的其他项目

贡献

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

请参阅调试测试文档以获取更多详细信息。

信用

感谢以下奇妙的套餐和人们辛勤的工作:

此列表可以继续…

许可证

麻省理工学院




相关问题推荐