From 509235bc5defb12fbf20d8e06d8c64824bc8bfab Mon Sep 17 00:00:00 2001 From: Eric Satterwhite Date: Fri, 6 Jan 2017 21:34:28 -0600 Subject: [PATCH] updating some timer docs --- README.md | 4 ++++ lib/server/index.js | 2 +- lib/timer.js | 22 +++++++++++++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d917e473..aa6dedb4 100644 --- a/README.md +++ b/README.md @@ -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 + + + # Install ``` diff --git a/lib/server/index.js b/lib/server/index.js index cfbd3d95..c9c64b7d 100644 --- a/lib/server/index.js +++ b/lib/server/index.js @@ -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); }); }); diff --git a/lib/timer.js b/lib/timer.js index 676dda5f..be485a5e 100644 --- a/lib/timer.js +++ b/lib/timer.js @@ -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; @@ -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 ;