New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

job-allocation

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

job-allocation

Library for distributing jobs between nodes

  • 2.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13
decreased by-48%
Maintainers
1
Weekly downloads
 
Created
Source

job-allocation

NPM Downloads

Library for distributing jobs between nodes

Install

yarn add job-allocation
# or
npm i job-allocation

Example

import {
    JAWorker,
    JARedisRemoteQueue,
    JAJob,
    createWaitJobsCompleted,
} from 'job-allocation';

const action = async (job: JAJob<{name: string}>) => `Hello world, ${job.data.name}`;
const remoteQueue = new JARedisRemoteQueue<{name: string}>({
    name: 'redis-key-queue',
    host: process.env.REDIS_HOST,
    port: process.env.REDIS_PORT,
});
const worker = new JAWorker({
    remoteQueue,
    action,
    concurrency: 2,
});
const { waitJobsCompleted } = createWaitJobsCompleted(worker);
const startTask = async () => {
    /**
     * Adding jobs to work
     */
    const jobs = await remoteQueue.add(
        { name: 'foo' },
        { name: 'bar' },
    );
    /**
     * Wait for the jobs to be completed
     * ! does not guarantee order
     */
    const jobsCompleted = await waitJobsCompleted(jobs);

    /**
     * Log the result:
     * Hello world, bar
     * Hello world, foo
     */
    jobsCompleted.forEach((job) => {
        console.log(job.returnData);
    });
};

/**
 * Run in nodes that perform tasks
 */
worker.start();
/**
 * Run in the control node
 */
startTask();

License

MIT

Keywords

FAQs

Package last updated on 25 Oct 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