# strapi-plugin-jobs/worker

:construction_worker: Helpers to make the implementation of a compatible worker easier. It listens for new jobs and puts the final and partial results in the proper database collection.

## Install

:pizza: First install the latest [Node.js](https://nodejs.org/download), [MongoDB](https://docs.mongodb.com/manual/installation) and [Redis](https://redis.io/download) stable versions.

```sh
npm i --save strapi-plugin-jobs
```

## Use
dbs
🚀 The simplest implementation example.

```js
const worker = require('strapi-plugin-jobs/worker');

const doJob = async (jobData, db) => {
  // Your implementation goes here.
  return jobData;
};

worker(doJob);
```

### API

👁 Full API definition.

#### `worker(doJob, opts)`

- `async doJob(jobData, db) -> result` (function): Custom implementation for the project.
  - `jobData` (object): Job information stored in the DB.
  - `db` (object): Mongo `db` instance, just in case you need to make other DB operations.
  - `result` (object): Information to store as the result of the job.
- `opts` (object): Optional parameters.
  - `dbs` (object): Databases options.
    - `queueUri` (string): URI to connect to the Redis queue. (default: `redis://127.0.0.1:6379`)
    - `dbUri` (string): URI to connect to the main database (MongoDB). (default: `mongodb://localhost:27017/strapi`)
  - `slack` (object): Slack settings for bug reporting.
    - `id` (string): Identifier for the current instance. (default: OS hostname)
    - `uri` (string): Webhook URI.
