We’re here to work with you at all stages.

View all services
Build products using the latest engineering practices and designs that aren’t just functional but beautiful with Launch.
Learn more
Rethink how your product delivery teams build and design your products. Architect to build the building blocks that allow experimentation with Amplify.
Learn more
Gain market share by designing and building product features. Gain velocity by embedding our experts in your team with Catalyse.
Learn more
Take control of your cloud costs and technical debt, and add coverage for DevOps with Control.
Learn more

Articles

From user research, digital strategy to solving bold engineering problems. Our team specialises in providing a suite of services that take an idea from a rough sketch to an enterprise grade product.
View all articles

Tutorials

Learning new technologies and frameworks ensures we are ahead of the curve. Here is a collection of step by step tutorials about things we've learnt. Learn with us!
View all tutorials

Products

We love open source, and we love giving back. Take a look at our open source products and how we're pushing the bounds of Engineering excellence one product at a time
View all products

Culture

We believe the best digital products are built by a diverse and skilled team. We’ve created a safe inclusive workspace, and we believe in diversity. We are a group that believes in software development and design is a craft. This is what unites us.
Learn more

Mission, Vision & Purpose

Our team is diverse. Each coming from a different background and beliefs. We think of product development & design as a craft. We love to learn new ways of improving our craft - be it learning new frameworks, or adding new specialties.
Learn more

White Papers

We believe the best digital products are built by a diverse and skilled team. We’ve created a safe inclusive workspace, and we believe in diversity. We are a group that believes in software development and design is a craft. This is what unites us.
Learn more

Wednesday Wisdom

Our team is diverse. Each coming from a different background and beliefs. We think of product development & design as a craft. We love to learn new ways of improving our craft - be it learning new frameworks, or adding new specialties.
Learn more

White Papers

We believe the best digital products are built by a diverse and skilled team. We’ve created a safe inclusive workspace, and we believe in diversity. We are a group that believes in software development and design is a craft. This is what unites us.
Learn more

Wednesday Wisdom

Our team is diverse. Each coming from a different background and beliefs. We think of product development & design as a craft. We love to learn new ways of improving our craft - be it learning new frameworks, or adding new specialties.
Learn more
View all tutorials
[Part 2] Executing batch jobs in a multi-container environment using NodeJS and express.
August 3, 2021
Mohammed Ali Chherawalla
Software Engineer
Contents

This is the second tutorial in a 3-Part series. If you haven’t completed the first tutorial 1, I would recommend going through it first here.

Create a CRON job to be executed at 12 am every day

In this step, we will register a CRON job that executes at 12 am every day. This CRON job will simply console log the time of execution and a static message.

Step 1

Add a new QUEUE_NAME called MIDNIGHT_CRON


export const QUEUE_NAMES = {
  SCHEDULE_JOB: 'scheduleJob',
  MIDNIGHT_CRON: 'midnightCron'
};

Step 2

Add a new processor for CRON


const CRON_EXPRESSIONS = {
  MIDNIGHT: '0 0 * * *'
};

export const QUEUE_PROCESSORS = {
   ...,
  [QUEUE_NAMES.MIDNIGHT_CRON]: (job, done) => {
		console.log({ job, done });
    console.log(`${moment()}::The MIDNIGHT_CRON is being executed at 12:00am`);
    done();
  }
};

Step 3

Register the CRON job in the server/utils/queue.js


export const initQueues = () => {
  ...
  queues[QUEUE_NAMES.MIDNIGHT_CRON].add({}, { repeat: { cron: CRON_EXPRESSIONS.MIDNIGHT } });
};

We will invoke the initQueues method from the server/index.js to initialize the queues on startup. After initializing the queues we will add a CRON job to be executed at 12 am.

You should see the below logs at 12 am!

🚀Feel free to update the regex and execute the CRON sooner than 12 am to test how it works.

Commit your code using the following git commands


git add .
git commit -m 'Add support to run a CRON job at 12 AM everyday'

Where to go from here

You now have the ability to set up CRON jobs in a multi-container environment.

I hope you enjoyed reading this article as much as I enjoyed writing it. If this piqued your interest stay tuned for the next article in the series where I will take you through how to write GraphQL subscriptions in a multi-container environment using  graphql-redis-subscriptions

If you have any questions or comments, please join the forum discussion on Twitter.

Wednesday is a boutique consultancy based in India & Singapore.

Let's talk

Wednesday is a boutique consultancy based in India & Singapore.

Let’s talk

2023