Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
priority-job-queue
Advanced tools
Readme
A client-side priority job queue.
Priority Job Queue iterates over a list of jobs to select and run the highest priority job. When a job is selected, it's 'fn' method is invoked with optional args and callback. The JobModel's status changes from 'queued' to 'running' and a status change event is fired.
When the job completes, the JobModel's status is changed to 'complete' and a status change is again fired. The queue also fires a 'queue change' event when a job is removed from the queue.
Typically jobs run serially but it's possible to run jobs in parallel by adding more than a single job to the JobModel. This way, a set of jobs would run to completion before the next job or job set was run.
The queue is controlled using a real-time clock that cycles each 1/10th of a second to inspect the queue status, find the highest priority job, and run it. The real-time chain enables modifying the priority of specific jobs, either up or down after they are added to the queue.
Although this module could be used server side, it was designed for client projects that use browserify. The ability to change priorities gives the user the ability to change the typical application behavior as they click through the application...
npm install priority-job-queue --save
The best way to see how the queue/job model work is to look at the examples below. The basics are
queue.startRealTimeTicker()
.new JobModel()
or queue.createJob()
job.fn = function(opts, callback) {};
queue.add( job )
If you add a job with a low or normal priority, then other jobs with a higher priority or older jobs with the same priority will run first.
The job runner is based on a real-time tick that evaluates queued jobs to select the highest priority then run it. The next tick repeats this process by first checking to see that there are no running jobs.
Since the entire queue is evaluated at each tick, a job's priority may change up or down while in the queue to move it up or down in the list.
When a job completes it's status is set to 'complete'. Or, if the job is re-occurring it will run, then set the scheduledTime to now() + the scheduledIdleTime. When it completes, it's status is set to idle so that it won't be removed from the list.
The priority job queue object selects the highest priority job from the list and runs it. It also searches for schedule jobs and runs them. A typical use would look like this:
var PriorityJobQueue = require('priority-job-queue').PriorityJobQueue,
JobModel = require('priority-job-queue').models.JobModel,
queue = PriorityJobQueue.createInstance();
var job = queue.createJob({ description:'my test job' });
// now implement the job...
job.fn = function(opts, callback) {
var err, results;
log.info('doing some work...');
// the callback must be invoked to signal the
// queue that the job has run
callback( err, results );
};
queue.add( job );
// start the internal ticker
queue.startRealTimeTicker();
TickEvent class was added to separate the one second tick from the job queue.
The JobModel is a data model with run logic for the contained job. The model contains status, priority, description, and pointers to the work-method, options and callback. When a job starts, the startTime is set; when it completes, completedTime is set. If the scheduledIdleTime is set, the job will run continually with idle time between runs, e.g., for memory cleanups, or any recurring job.
JobModelEvent has it's own class to enable requiring the listeners for the event class without loading the model.
PriorityJobQueue examples can be foound in the examples folder. The two types are command line scripts and in-browser compiled with browserify.
The browser example is 'index.html' in the examples folder. You can run it by pointing your browser to the file or, if you have http-server you can do this:
cd examples
http-server -p 3000 -o
The example will run on port 3000. If you have browserify installed you may modify the browser example in examples/main.js then run make bundle
to compile the changes.
gulp test
// or
make test
// or
npm test
// or
make watch
Currently no mocks but the test/fixtures folder has a JobQueueDataset to create lists of jobs for testing.
copyright © 2014-2015 rain city software | version 0.90.30
FAQs
A client-side priority job queue
The npm package priority-job-queue receives a total of 11 weekly downloads. As such, priority-job-queue popularity was classified as not popular.
We found that priority-job-queue 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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.