Extending BCMS Jobs

BCMS Jobs are JavaScript functions that execute at a specified time interval.

Creating a BCMS job

Create a file inside src/jobs folder, for example, test.ts.

To keep it simple, this job will only console log Hello world! message.

src/jobs/test.ts

import { createBcmsJob } from '@becomes/cms-backend/src/job';

export default createBcmsJob(async () => {
  return {
    cron: {
      dayOfMonth: '*',
      dayOfWeek: '*',
      hour: '*',
      minute: '*',
      month: '*',
    },
    async handler() {
      console.log('Hello world!');
    },
  };
});

The job will run every minute. The time is set using Cron time format. Crontab guru is an amazing website which allows you to calculate time intervals.


Deploying a job

When you are ready to deploy your job to the CMS, follow these steps:

  • Inside the project, run npm run bundle. This will compile TypeScript files and bootstrap the project.
  • Then, to deploy your job, run npm run deploy.