strapi-plugin-jobs

3.0.0-beta.18.11 • Public • Published

strapi-plugin-jobs

Build Status

👷 Strapi plugin to support background jobs.

  • Simpe, thought for prototyping.
  • Generic enough to support different kind of applications.
  • Support bull as the queue engine.
  • Job inputs, results and metadata storage in MongoDB.
  • Jobs info download in JSON format.
    • Filtering by date.
  • Worker implementation example provided.

Once the plugin is added to your application a new collection Jobs (jobs_Job in the database) will appear and a new plugin with the same name.

Strapi panel

Collection fields

job fields

To learn about Strapi plugins you can visit the official documentation.

Note: This component is in beta (v0.x.x), so please check the CHANGELOG to learn about any change in your code.

Install & use

🍕 Inside a project folder.

npm i --save strapi-plugin-jobs
npm i --save-dev axios # temporal workaround 
npm run build

Environment

The plugin rely on external services, so it expects to find the next environment variables.

  • DATABASE_URI: MongoDB URI, as the main database engine. For now we don't support the Strapi in-memory provider (useful to develop).
  • QUEUE_URI: The queue (Redis) connection string for the queue.

DB setup

A new model Job is included, so you need to add the next entry in your User.settings.json.

"jobs"{
  "collection": "job",
  "via": "owner",
  "plugin": "users-permissions"
}

Input checks

Any object is supported as input.

Optionally, you can define a global policy to check the input field of the jobs. The file needs to be called isValid.js. In example:

module.exports = async (ctx, next) => {
  const { input } = ctx.request.body; // marked as required
 
  // TODO: Add to the doc.
  if (!input.myField1 || !input.myField2) {
    return ctx.throw(400);
  }
 
  if (typeof input.myField1 !== 'string' || typeof input.myField2 !== 'string') {
    return ctx.throw(400);
  }
 
  return next();
};

Worker

The use of this plugin implies the need of a worker to resolve the jobs put in the queue by this HTTP API. It should also write the result directly into the database.

It uses to be very attached to each project, so we provide this helper to make the things easier.

Readme

Keywords

none

Package Sidebar

Install

npm i strapi-plugin-jobs

Weekly Downloads

1

Version

3.0.0-beta.18.11

License

UNLICENSED

Unpacked Size

28.7 kB

Total Files

38

Last publish

Collaborators

  • jesusprubio