npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@knfs-tech/bamimi-schedule

v1.0.1

Published

Schedule module

Downloads

22

Readme

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",
    isCronJob: true,
    options: { repeat: { cron: "0 * * * *" } },
    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

  • jobs: Object[] An array of job definitions.

    Each job object should have the following properties:

    • queue: string The name of the queue to be used for the job.

    • name: string The name of the job to be added to the queue.

    • isCronJob: boolean Indicates whether the job is a cron job.

    • options: Object (optional, default: {}) Additional options for the job, such as scheduling and job-specific settings.

    • handle: Function The handler function for processing the job.

  • queueManager: QueueManager An instance of QueueManager used for managing queues and workers.

Returns

  • Promise<void> A promise that resolves when all queues and workers have been initialized.

Events

Workers listen for the following events:

  • completed: Fired when a job completes successfully.

    Job <jobID> completed successfully
  • failed: Fired when a job fails.

    Job <jobID> failed with error <error.message>

Example Jobs Array

Here is an example of a jobs array:

const jobs = [
  {
    queue: "emailQueue",
    name: "sendWelcomeEmail",
    isCronJob: false,
    options: { priority: 1 },
    handle: async (job) => {
      // Job handler logic for sending welcome emails
    }
  },
  {
    queue: "reportQueue",
    name: "generateMonthlyReport",
    isCronJob: true,
    options: { repeat: { cron: "0 0 1 * *" } },  // 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.