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

minionjs-backend-mongoose

v0.1.3

Published

A Mongoose backend for minion.js

Downloads

15

Readme

Mongoose backend for minion.js

npm package Build workflow Coverage Status Last Commit Dependencies Downloads

A Mongoose Backend written in Typescript/ES6 for minion.js, a high performance job queue for Node.js

Installation

npm i minionjs-backend-mongoose -s

Usage

import Minion from '@minionjs/core';
import MongooseBackend from 'minionjs-backend-mongoose';

// Use the high performance MongoDB backend
const uri = 'mongodb://user:password@localhost:27017/database?authSource=admin'
const minion = new Minion({uri: uri}, {backendClass: MongooseBackend}));
// or
// await mongoose.connect(uri);
// const minion = new Minion(mongoose, { backendClass: MongooseBackend });

// Add tasks
minion.addTask('somethingSlow', async (job, ...args) => {
  console.log('This is a background worker process.');
});

// Add hook before job started
minion.addJobHook('job:before', (minion, job) => {
  minion.app.log.trace(`Performing job "${job.id}" with task "${job.task}"`);
});

// Enqueue jobs
await minion.enqueue('somethingSlow', ['foo', 'bar']);
await minion.enqueue('somethingSlow', [1, 2, 3], {priority: 5});

// Perform jobs for testing
await minion.enqueue('somethingSlow', ['foo', 'bar']);
await minion.performJobs();

// Start a worker to perform up to 12 jobs concurrently
const worker = minion.worker();
worker.status.jobs = 12;
await worker.start();

console.log("Worker started and is waiting for other jobs");

process.on('SIGINT', async () => {
  console.log("Stopping worker...");
  await worker.stop();
  console.log("Shutdown minion");
  await minion.end();
})

Or using mojo.js framework and typescript

// node script.js minion-worker -j 12
// to start a worker to perform up to 12 jobs concurrently

import { minionPlugin } from '@minionjs/core';
import mojo, { MojoApp } from '@mojojs/core';
import MongooseBackend from 'minionjs-backend-mongoose';

const uri = 'mongodb://user:password@localhost:27017/database?authSource=admin'

export const app: MojoApp = mojo();

app.plugin(minionPlugin, { config: { uri: uri }, backendClass: MongooseBackend });

const minion = app.models.minion;

// Add tasks
minion.addTask('somethingSlow', async (job, ...args) => {
    console.log('This is a background worker process with id %s and args %s', job.id, args);
});

// Add hook before job started
minion.addJobHook('job:before', (minion, job) => {
    minion.app.log.trace(`Performing job "${job.id}" with task "${job.task}"`);
});

// Enqueue jobs
await minion.enqueue('somethingSlow', ['foo', 'bar']);
await minion.enqueue('somethingSlow', [1, 2, 3], { priority: 5 });

// Perform jobs for testing
await minion.enqueue('somethingSlow', ['foo', 'bar']);
await minion.performJobs();

app.start();

console.log("App is started and is waiting for other jobs");

process.on('SIGINT', async () => {
    console.log("Shutdown minion");
    await minion.end();
})

Now send some other jobs to these workers.

import Minion from '@minionjs/core';
import MongooseBackend from 'minionjs-backend-mongoose';
import mongoose from 'mongoose';

const uri = 'mongodb://user:password@localhost:27017/database?authSource=admin'

await mongoose.connect(uri);
const minion = new Minion(mongoose, {backendClass: MongooseBackend});

const id = await minion.enqueue('somethingSlow', ['a', 'b', 'c']);
console.log("Enqueued job with id", id);

await minion.end();

and look to worker output to see that the job has been processed.

See Minion.js documentation for other examples.

Bugs / Help / Feature Requests / Contributing

Author

Emiliano Bruni - [email protected]

License

Licensed under GNU GPLv3