Latest Threat Research:Malicious dYdX Packages Published to npm and PyPI After Maintainer Compromise.Details
Socket
Book a DemoInstallSign in
Socket

level-schedule

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

level-schedule

Durable job scheduler based on LevelDB

Source
npmnpm
Version
0.0.1
Version published
Weekly downloads
8
Maintainers
1
Weekly downloads
 
Created
Source

level-schedule

Durable job scheduler based on LevelDB.

Usage

Print some JSON after 5s, even if the process restarts.

var levelup = require('levelup');
var Schedule = require('level-schedule');

var db = levelup('./db');

Schedule(db)
  .job('print', function (payload) {
    console.log(payload);
  })
  .run('print', { some : 'json' }, Date.now() + 5000);

// => { some : 'json' }

Periodic tasks

Run a task every 100ms. Always call this.run at the end of the task, otherwise if the process crashes while running your task it will be scheduled once too many.

Schedule(db)
  .job('periodic', function () {
    console.log('doing some stuff...');
    this.run('periodic', Date.now() + 100)
  })
  .run('periodic', Date.now() + 100);

Jobs

A job can be synchronous or asynchronous, just use the done argument when defining an asynchronous job.

Schedule(db)
  .job('sync', function (payload) {
    if (somethingBadHappend) {
      throw new Error();
    }
  })
  .job('async', function (payload, done) {
    // notice the 2nd argument
    doSomething(function (err) {
      done(err);
    });
  })
  .on('error', console.error)
  .run('sync')
  .run('async');

API

Schedule(db[, prefix])

Setup level-schedule to use db, storing tasks under prefix (defaults to schedule!).

Schedule#job(name, fn)

Register a job with name and fn.

fn is called with 2 arguments:

  • payload : The payload
  • done : If the job performs async operations, call done() when done. If an error occured you can pass that as an error argument to done.

Schedule#run(job[, payload], timestamp)

Run job with payload at timestamp.

Schedule#on('error', fn)

Call fn whenever an Error occurs. When no error listener has been registered, errors will be thrown.

Installation

With npm do

$ npm install level-schedule

License

(MIT)

Keywords

schedule

FAQs

Package last updated on 01 Apr 2013

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