> For the complete documentation index, see [llms.txt](https://docs.obto.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.obto.co/applications/scheduled-jobs.md).

# Scheduled Jobs

Scheduled Jobs are automated scripts that can perform a specific task at a specific time or on a recurring schedule. Eg - Sending notifications to users whose subscription has expired.

Fill the following details to create a schedule job :-\
**Name** - name of the schedule job\
**Active** - chech / uncheck to activate / deactivate the job.\
**State** - state shows whether the job is running or not.\
**Job Type** :-\
&#x20;    **Interva**l - job will run every interval defined by the cron pattern.\
&#x20;    **On Demand** - job will run only with manual intervention whenever you want it to run.\
**Schedule** - provide cron pattern here like \*/1 \* \* \* \* which means job will run every minute.

Below is a sample code to delete stale logs and events generated by the platform.

```javascript
const DB = ob.db.getConnection();
DB.collection('pltf_log').deleteMany({
  created_on: {
    $lte: new Date(
      ob.moment
        .tz('Asia/Kolkata')
        .subtract(15, 'days')
        .startOf('day')
        .toISOString()
    )
  }
});

DB.collection('pltf_event_queue').deleteMany({
  created_on: {
    $lte: new Date(
      ob.moment
        .tz('Asia/Kolkata')
        .subtract(15, 'days')
        .startOf('day')
        .toISOString()
    )
  }
});

DB.collection('pltf_transaction').deleteMany({
  created_on: {
    $lte: new Date(
      ob.moment
        .tz('Asia/Kolkata')
        .subtract(100, 'days')
        .startOf('day')
        .toISOString()
    )
  }
});

DB.collection('deleted').deleteMany({
  created_on: {
    $lte: new Date(
      ob.moment
        .tz('Asia/Kolkata')
        .subtract(90, 'days')
        .startOf('day')
        .toISOString()
    )
  }
});

```
