> 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="/files/6Dt21wCBGNdXnQXynK63" 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="/files/x2WjQrEsUH9trRVsJRVR" 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="/files/KQxmUt4ThzwOk48fmqtt" 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 %}
