strapi-plugin-jobs
👷 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.
Collection 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-jobsnpm 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":
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:
moduleexports = async { const input = ctxrequestbody; // marked as required // TODO: Add to the doc. if !inputmyField1 || !inputmyField2 return ctx; if typeof inputmyField1 !== 'string' || typeof inputmyField2 !== 'string' return ctx; return ;};
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.