topliceanu / schedule-drone

A reliable, fault-tolerant, persistent event scheduler for node.js
5 stars 4 forks source link

schedule-drone

Build Status

A reliable , fault-tolerant, persistent event scheduler for node.js It achieves it's resiliance by storing event configurations on disk. Currently only MongoDB persistance is supported.

Install

npm install schedule-drone

Development

git clone git@github.com:topliceanu/schedule-drone.git
cd schedule-drone
npm install
npm test # To run the tests.
npm build # To build the js files that are published to npm

Example

drone = require 'schedule-drone'
drone.setConfig
    persistence:
        type: 'mongodb'
        connectionString: 'mongodb://localhost:27017/scheduled-events'
        options: {} # Some mongodb driver options here.

scheduler = drone.daemon()

# Add a one-time event scheduled in the future, given a Date instance.
scheduler.schedule dateInFuture, 'my-one-time-event', params

# Add the cyclic event using the standard unix cron syntax.
scheduler.schedule '* * * * * 1', 'my-cron-event', params

scheduler.on 'my-one-time-event', (params) ->
    # Do something awesome

Api

drone.setConfig() - pass in configuration needed for the module's api to work. At the very least the connection string to the persistence layer must be supplied.

drone.daemon() - start the scheduler daemon. It listens to new scheduled events, stores then, and triggeres them appropriately. Returns an instance of a PersistenceScheduler.

class PersistentScheduler - inherits from events.EventEmitter

PersistenceScheduler.schedule(when:String|Date, event:String, data:Object, callback:Function)

PersistenceScheduler.scheduleAndStore(when:String|Date, event:String, data:Object, callbac:Function)

drone.schedule(dataOrCronString, eventName, eventPayload, callback)

Licence

MIT Licence

Copyright (C) 2013 alexandru.topliceanu@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.