How to create and use BCMS Jobs?

By Branislav Vajagić
Read time 1 min
Posted on October 31, 2022
Share it on:
Hook you custom logic to internal BCMS Jobs.

BCMS Jobs are simply said, CRON Jobs, which will run at the specified intervals. The only difference is that you do not need to learn Bash Scripts, and you have access to BCMS resources.

How to create a BCMS Job?

We will use local BCMS to develop and test the Job, and after that, we will see how to deploy it to live BCMS.

Creating a Job is as simple as creating a new file inside of the ./src/jobs and adding configuration to it. You can do something like this:

// File: ./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(new Date().toISOString());
    },
  };
});
          

As easy as that! As you can see, this Job will be executed every minute and every minute handler the method will be called. If you are not familiar with the CRON job time format, you can use CRON Guru, which will make your life much easier.

Deploying BCMS Jobs

This step is the same as with Functions and Events. In your BCMS project, just run npm run bundle. This will bundle and prepare all your resources to be deployed to the live BCMS. Once that is done, run npm run deploy. You will be asked to select a BCMS Instance to which you want to deploy your code. After that, your code will be live, and you can interact with it.

  • It takes a minute

  • Free support

  • 14 days free trial

Create your account