Skip to content

Commit

Permalink
updating some timer docs
Browse files Browse the repository at this point in the history
  • Loading branch information
esatterwhite committed Jan 7, 2017
1 parent 4711e1c commit 509235b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
A distributed reliable timer service providing similar functionality to using `setTimeout`.
`Skyring` servers are clustered into a *hashring* using consistent hashing to partition timers to specific nodes in the ring. Skyring exposes a simple HTTP API That allows to you create and cancel timers. Timer execution comes in to the form of an HTTP webhook ( more transports to come )

# Architechture Overview

<img src="https://raw.githubusercontent.com/esatterwhite/skyring/master/assets/skyring-arch.png" width="100%" max-width="800px">

# Install

```
Expand Down
2 changes: 1 addition & 1 deletion lib/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Server extends http.Server {
this._timers = new Timer({nats: this.options.nats});
this._router = new Router(this._node, this._timers);
this._node.on('ringchange', (evt) => {
this._timers.rebalance(evt, this._node, (data) => {
this._timers.rebalance(evt, (data) => {
this.proxy(data);
});
});
Expand Down
22 changes: 21 additions & 1 deletion lib/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,31 @@ class Timer extends Map {
* @param {Object} body Configuration options for the timer instance
* @param {Number} body.timeout Duration in milisecods to delay execution of the timer
* @param {String} body.data The data to be assicated with the timer, when it is executed
* @param {Number} [body.created=Date.now()] timestamp when the timer is created. if not set, will default to now
* @param {Object} callback Options for the outbound transport for the timer when it executes
* @param {String} callback.transport The transport type ( http, etc )
* @param {String} transport.method The method the transport should use when executing the timer
* @param {String} transport.uri The target uri for the transport when the timer executes
* @param {Nodeback} callback
* @example
const crypto = require('crypto')
id = crypto.createHash('sha1')
.update(crypto.randomBytes(10))
.digest('hex')
const options = {
timeout: 4000
, data: "this is a payload"
, callback: {
transport: 'http'
, method: 'put
, uri: 'http://api.domain.com/callback'
}
}
timers.create(id, options, (err) => {
if (err) throw err
})
**/
create(id, body, cb) {
const payload = body;
Expand Down Expand Up @@ -118,7 +138,7 @@ class Timer extends Map {
cb && setImmediate(cb, null);
}

rebalance(opts, node, cb) {
rebalance(opts, cb) {
const callback = cb || noop
, size = this.size
;
Expand Down

0 comments on commit 509235b

Please sign in to comment.