> For the complete documentation index, see [llms.txt](https://abyss-project.gitbook.io/abyss-monitor/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://abyss-project.gitbook.io/abyss-monitor/tutorials/distributed-cron-task.md).

# Distributed Cron Task

AbyssMonitor provide an easy way to setup Cron Task using a distributed manager.\
From this tools, you will be able to create a secured task insuring trigger and logging.

### Workflow

<img src="https://1786693184-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUbQ9ibSNpbsJCfDpK7GR%2Fuploads%2FxoNRKU6i6cDdxPxKADGP%2Ffile.excalidraw.svg?alt=media&amp;token=a818a44b-3bfd-4e77-bc96-fcf256c3faa6" alt="Workflow for distributed Cron Task on AbyssMonitor" class="gitbook-drawing">

### Setup

First, you have to create a new Cron Task on your Application interface.

<figure><img src="https://1786693184-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUbQ9ibSNpbsJCfDpK7GR%2Fuploads%2Fywj10LfU7uzBPQNgD8AV%2Fcron-task.png?alt=media&amp;token=37a90739-a1b7-40b2-b405-c2caff1472ab" alt=""><figcaption><p>Cron Task creation form</p></figcaption></figure>

A new card is added. You can edit your Cron Task and copy the secret signature.

<figure><img src="https://1786693184-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUbQ9ibSNpbsJCfDpK7GR%2Fuploads%2FpZz7CZWDoaQpkuMLpTNf%2Fcron-task-2.png?alt=media&amp;token=04b1d038-a7a3-421d-960e-7dcc18b50aca" alt=""><figcaption><p>Cron Task secret</p></figcaption></figure>

### Authentifie Cron Task request

Using the secret signature, you can authentifie the request.

{% code overflow="wrap" lineNumbers="true" %}

```typescript
import {
  HEADER_SIGNATURE_NAME,
  SIGNATURE_ALGORITHM,
} from '@abyss-project/monitor';

const headerSignature = req.headers[HEADER_SIGNATURE_NAME];

const hmac = crypto.createHmac(
  SIGNATURE_ALGORITHM,
  "my-secret-signature",
);
const signature = hmac.update(JSON.stringify(req.body)).digest('hex');

if (headerSignature !== signature) {
  // Throw an error
  throw new Error('Invalid Signature');
}
// The signature is correct

// Response with the requestId of the AbyssMonitor logger to link logs to the cronTask
// ex: res.status(200).json(getRequestContext().requestId);
```

{% endcode %}

{% hint style="info" %}
Your Cron Task can generate logs. Logs will be linked to the Cron Task to debug easily.

Check code example above.
{% endhint %}
