Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@egomobile/queue-mongo

Package Overview
Dependencies
Maintainers
5
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@egomobile/queue-mongo

Queue storage for node-queue, using MongoDB as backend.

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
increased by200%
Maintainers
5
Weekly downloads
 
Created
Source

npm last build PRs Welcome

@egomobile/queue-mongo

Queue storage for @egomobile/queue, using MongoDB as backend.

Install

Execute the following command from your project folder, where your package.json file is stored:

npm install --save @egomobile/queue-mongo

Usage

import { Queue } from "@egomobile/queue";
import {
  IMongoQueueStorageOptions,
  MongoQueueStorage,
} from "@egomobile/queue-mongo";
import { MongoClient } from "mongodb";

let queue!: Queue;

async function main() {
  const url = process.env.MONGO_URL?.trim() || "mongodb://localhost:27017";
  const mongoClient = new MongoClient(url);
  const db = mongoClient.db("my_database");

  const storageOptions: IMongoQueueStorageOptions = {
    getDb: () => {
      return db;
    },
  };

  queue = new Queue({
    storageClass: MongoQueueStorage,
    storageClassArgs: [storageOptions],
  });

  // register 2 tasks at once
  queue.register({
    // 1st
    myTask1: async (context) => {
      console.log("This is task 1 with following data:", context.data);
    },

    // 2nd
    myTask2: async (context) => {
      console.log("This is task 2 with following data:", context.data);
    },
  });

  // anything is prepared, lets start the queue
  await queue.start();

  // first enqueue 2nd task
  await queue.enqueue("myTask2", {
    data: {
      buzz: 5979,
    },
  });
  // then 1st one
  await queue.enqueue("myTask1", {
    data: {
      foo: "bar",
    },
  });
}

main().catch(console.error);

Documentation

The API documentation can be found here.

Keywords

FAQs

Package last updated on 11 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc