Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
The qjobs npm package is a lightweight, fast job queue manager for Node.js. It allows for efficient management of tasks with the ability to limit the number of concurrent jobs, making it suitable for scenarios where resource management and job scheduling are critical. It's particularly useful for managing CPU-intensive tasks or IO-bound operations in a controlled manner.
Job scheduling and concurrency control
This feature allows you to schedule jobs and control the number of jobs running concurrently. In the code sample, a new QJobs instance is created with a maximum concurrency of 5, meaning no more than 5 jobs will run at the same time. Jobs are added to the queue and executed with controlled concurrency.
const QJobs = require('qjobs');
const myQueue = new QJobs({maxConcurrency: 5});
const myJob = function(args, next) {
console.log('Working on job with args', args);
next();
};
for (let i = 0; i < 10; i++) {
myQueue.add(myJob, [i]);
}
myQueue.run();
Job completion and error handling
This feature demonstrates how to handle job completion and errors. Jobs are defined with a condition to either complete successfully or fail. The QJobs instance listens for 'end' and 'error' events to handle job completion and errors respectively. This allows for robust error handling and notification upon job queue completion.
const QJobs = require('qjobs');
const myQueue = new QJobs();
const myJob = function(args, next) {
if (args.shouldFail) {
throw new Error('Job failed');
} else {
console.log('Job completed successfully');
next();
}
};
myQueue.on('end', function() {
console.log('All jobs have been processed');
});
myQueue.on('error', function(err) {
console.error('Error processing job:', err);
});
myQueue.add(myJob, [{shouldFail: false}]);
myQueue.add(myJob, [{shouldFail: true}]);
myQueue.run();
Bull is a more feature-rich job and message queue package for Node.js, built on top of Redis. It offers advanced functionalities such as delayed jobs, repeatable jobs, job prioritization, and more. Compared to qjobs, Bull is better suited for applications requiring complex job management features and persistence.
Kue is a priority job queue backed by Redis, focusing on job creation, processing, and management. It provides a rich set of features like job events, job prioritization, and a UI for monitoring. While Kue offers more advanced features compared to qjobs, it's also heavier and may require more setup due to its Redis dependency.
Bee-queue is a simple, fast, and robust job/task queue for Node.js, also backed by Redis. It's designed for high-performance and reliability, supporting job progress, retries, and failures. Bee-queue is a good middle ground between qjobs and more complex solutions like Bull, offering a balance of simplicity and functionality.
Efficient queue job manager module for nodejs.
Jobs which needs to run in parallels, but in a controled maner, example:
(take a look at tests directory if you are looking for running samples)
var qjobs = new require('./qjobs');
// My non blocking main job
var myjob = function(args,next) {
setTimeout(function() {
console.log('Do something interesting here',args);
next();
},1000);
}
var q = new qjobs({maxConcurrency:10});
// Let's add 30 job to the queue
for (var i = 0; i<30; i++) {
q.add(myjob,[i,'test '+i]);
}
q.on('start',function() {
console.log('Starting ...');
});
q.on('end',function() {
console.log('... All jobs done');
});
q.on('jobStart',function(args) {
console.log('jobStart',args);
});
q.on('jobEnd',function(args) {
console.log('jobend',args);
// If i'm jobId 10, then make a pause of 5 sec
if (args._jobId == 10) {
q.pause(true);
setTimeout(function() {
q.pause(false);
},5000);
}
});
q.on('pause',function(since) {
console.log('in pause since '+since+' milliseconds');
});
q.on('unpause',function() {
console.log('pause end, continu ..');
});
q.run();
//q.abort() will empty jobs list
FAQs
qjobs is a simple and stupid queue job manager for nodejs
The npm package qjobs receives a total of 2,190,059 weekly downloads. As such, qjobs popularity was classified as popular.
We found that qjobs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.