bamimi-schedule


<a href="https://scrutinizer-ci.com/g/knfs-library/bamimi-schedule/build-status/master"alt="scrutinizer"> Build Status</a> <a href="https://scrutinizer-ci.com/g/knfs-library/bamimi-schedule/?branch=master"alt="scrutinizer"> Scrutinizer Code Quality</a> <a href="https://github.com/knfs-library/bamimi-schedule/actions"alt="scrutinizer"> github</a>

About Bamimi schedule

This is a package that helps you manage basically queue and job


Install

npm i @knfs-tech/bamimi-schedule
#or
yarn add @knfs-tech/bamimi-schedule

Overview

The job function sets up queues and workers according to the job definitions provided. It supports scheduling jobs as cron jobs and provides logging for job completion and failure.

Usage

To use the job function, import it and provide it with the necessary parameters.

Example


const { job, QueueManager } = require("@knfs-tech/bamimi-schedule");

const jobs = [
  {
    queue: "testQueue",
    name: "testJob",
    schedules: [
      {
        name: "first-day-every-month",
        time: {
          pattern: "0 0 1 * *"
        }, // cron schedule
        prepare: { data: { email: "test@example.com" } },
      },
    ],
    options: {},
    handle: async (job) => { /* Job handler function */ }
  }
];

const queueManager = QueueManager.getInstance({
  storage: {
    host: "localhost",
    port: 6379
  }
});

job(jobs, queueManager)
  .then(() => {
    console.log("All jobs initialized");
  })
  .catch((err) => {
    console.error("Error initializing jobs:", err);
  });

Function Details

Initializes queues and workers for each job in the provided jobs array. If a job is marked as a cron job (isCronJob is true), it schedules the job accordingly.

Parameters

Returns

Events

Workers listen for the following events:

Example Jobs Array

Here is an example of a jobs array:

const jobs = [
  {
    queue: "emailQueue",
    name: "sendWelcomeEmail",
    options: { priority: 1 },
    handle: async (job) => {
      // Job handler logic for sending welcome emails
    }
  },
  {
    queue: "reportQueue",
    name: "generateMonthlyReport",
    schedules: [
      {
        name: "first-day-every-month",
        time: {
          pattern: "0 0 1 * *"
        }, // cron schedule
        prepare: { data: { email: "test@example.com" } },
      },
    ],  // Runs on the first day of every month
    handle: async (job) => {
      // Job handler logic for generating reports
    }
  }
];

Author

Owner

More

License

Bamimi is open-sourced software licensed under the MIT license.