Skip to content

Commit

Permalink
docs: update the transport docs to illustrate classes
Browse files Browse the repository at this point in the history
update the docs to illustrate the useage of transport classes
  • Loading branch information
esatterwhite committed May 12, 2019
1 parent a4891e8 commit a9c3afb
Show file tree
Hide file tree
Showing 43 changed files with 174 additions and 474 deletions.
2 changes: 1 addition & 1 deletion docs/api/api_project.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ define({
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2019-05-05T14:24:25.618Z",
"time": "2019-05-12T03:48:56.189Z",
"url": "http://apidocjs.com",
"version": "0.17.7"
}
Expand Down
2 changes: 1 addition & 1 deletion docs/api/api_project.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2019-05-05T14:24:25.618Z",
"time": "2019-05-12T03:48:56.189Z",
"url": "http://apidocjs.com",
"version": "0.17.7"
}
Expand Down
2 changes: 1 addition & 1 deletion docs/classes.list.html
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>

on 2019-05-05T09:24:25-05:00
on 2019-05-11T22:48:55-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
6 changes: 1 addition & 5 deletions docs/global.html
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,6 @@ <h4 class="name" id="module:skyring/lib/transports/http"><span class="type-signa
<dd>


<div class="description">
<p>Dispatches an http request</p>
</div>




Expand Down Expand Up @@ -820,7 +816,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>

on 2019-05-05T09:24:25-05:00
on 2019-05-11T22:48:55-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
8 changes: 4 additions & 4 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@


<section class="readme-section">
<article><p><img src="https://github.com/esatterwhite/skyring/raw/master/assets/skyring-inverted.png" alt="skyring"></p>
<article><p><img src="https://github.com/esatterwhite/skyring/raw/master/assets/skyring.png" alt="skyring"></p>
<p><a href="skyring"><img src="https://img.shields.io/travis/esatterwhite/skyring/master.svg?style=flat-square" alt="Travis branch"></a>
<a href="https://www.npmjs.com/package/skyring"><img src="https://img.shields.io/npm/v/skyring.svg?style=flat-square" alt="npm"></a>
<a href="https://github.com/esatterwhite/skyring"><img src="https://img.shields.io/npm/l/skyring.svg?style=flat-square" alt="npm"></a>
Expand All @@ -120,7 +120,7 @@
</ul>
<h1>Skyring</h1><p>A distributed reliable timer service providing <code>setTimeout</code> functionality in a distributed fashion.
<code>Skyring</code> servers are clustered into a <em>hashring</em> 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 )</p>
<h1>Architecture Overview</h1><p><img src="https://raw.githubusercontent.com/esatterwhite/skyring/master/assets/skyring-arch-inverted.png" width="100%" max-width="800px"></p>
<h1>Architecture Overview</h1><p><img src="https://raw.githubusercontent.com/esatterwhite/skyring/master/assets/skyring-arch.png" width="100%" max-width="800px"></p>
<h1>Install</h1><pre class="prettyprint source"><code>npm install -s skyring</code></pre><h2>Run A Local Cluster</h2><h3>Start a nats instance</h3><p>Download the <a href="https://github.com/nats-io/gnatsd/releases">nats binary</a> and start it using the defaults</p>
<pre class="prettyprint source lang-bash"><code>$ gnats -D -V</code></pre><p>To verify that it is working, you can <code>telnet</code> directly to the server and ping it.</p>
<pre class="prettyprint source lang-bash"><code>$ telnet localhost 4222
Expand Down Expand Up @@ -274,7 +274,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>

on 2019-05-05T09:24:25-05:00
on 2019-05-11T22:48:55-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down Expand Up @@ -365,4 +365,4 @@ <h4 class="modal-title">Search results</h4>


</body>
</html>
</html>
2 changes: 1 addition & 1 deletion docs/index.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>

on 2019-05-05T09:24:25-05:00
on 2019-05-11T22:48:54-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/lib_json.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>

on 2019-05-05T09:24:25-05:00
on 2019-05-11T22:48:54-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/lib_nats.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>

on 2019-05-05T09:24:25-05:00
on 2019-05-11T22:48:54-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/lib_server_index.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>

on 2019-05-05T09:24:25-05:00
on 2019-05-11T22:48:54-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/lib_server_node.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>

on 2019-05-05T09:24:25-05:00
on 2019-05-11T22:48:54-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/lib_server_request.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>

on 2019-05-05T09:24:25-05:00
on 2019-05-11T22:48:54-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/lib_server_response.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>

on 2019-05-05T09:24:25-05:00
on 2019-05-11T22:48:54-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/lib_server_route.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>

on 2019-05-05T09:24:24-05:00
on 2019-05-11T22:48:54-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/lib_server_router.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>

on 2019-05-05T09:24:25-05:00
on 2019-05-11T22:48:54-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
8 changes: 4 additions & 4 deletions docs/lib_timer.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ <h1 class="page-title">Source: lib/timer.js</h1>
**/
create(id, body, cb) {
const payload = body;
const transport = this.transports[payload.callback.transport];
const transport = this.transports.get(payload.callback.transport);
if (!transport) {
const err = new Error(`Unknown transport ${payload.callback.transport}`)
err.code = 'ENOTRANSPORT'
Expand All @@ -263,7 +263,7 @@ <h1 class="page-title">Source: lib/timer.js</h1>
if( now > created + payload.timeout ){
debug('executing stale timer');
setImmediate(
transport
transport.exec.bind(transport)
, payload.callback.method
, payload.callback.uri
, payload.data
Expand Down Expand Up @@ -307,7 +307,7 @@ <h1 class="page-title">Source: lib/timer.js</h1>
}), noop);

data.timer = setTimeout(
transport
transport.exec.bind(transport)
, payload.timeout - elapsed
, payload.callback.method
, payload.callback.uri
Expand Down Expand Up @@ -653,7 +653,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>

on 2019-05-05T09:24:25-05:00
on 2019-05-11T22:48:54-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
19 changes: 16 additions & 3 deletions docs/lib_transports_callback.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,24 @@ <h1 class="page-title">Source: lib/transports/callback.js</h1>
* @module skyring/lib/transports/timer
* @author Eric Satterwhite
* @since 1.0.4
* @requires skyring/lib/transports/transport
*/

module.exports = function callback( method, url, payload, id ){
setImmediate(payload[method], url, id);
const Transport = require('./transport')
class Callback extends Transport {
constructor(options) {
super(options)
}

exec( method, url, payload, id, cache ) {
setImmediate(() => {
payload[method](url, id)
return cache.success(id);
});
}
};

module.exports = Callback
</pre>
</article>
</section>
Expand Down Expand Up @@ -148,7 +161,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>

on 2019-05-05T09:24:25-05:00
on 2019-05-11T22:48:55-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
73 changes: 43 additions & 30 deletions docs/lib_transports_http.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ <h1 class="page-title">Source: lib/transports/http.js</h1>
<pre
class="sunlight-highlight-javascript ">/*jshint laxcomma: true, smarttabs: true, node:true, esnext:true*/
'use strict';

/**
* The Http transport backend
* @module skyring/lib/transports/http
Expand All @@ -107,6 +108,7 @@ <h1 class="page-title">Source: lib/transports/http.js</h1>
const STATUS_CODES = require('http').STATUS_CODES
, request = require('request')
, debug = require('debug')('skyring:transport:http')
, Transport = require('./transport')
, method_exp = /^(post|put|patch|delete|get|options|head)$/i
;

Expand All @@ -120,41 +122,52 @@ <h1 class="page-title">Source: lib/transports/http.js</h1>
* @param {String} id The id of the timer being executed
* @param {module:skyring/lib/timer} cache A timer cache instance to delete from after execution
**/
module.exports = function httpTransport( method, url, payload, id, cache ) {
const isJSON = typeof payload === 'object'
, _method = method.toLowerCase()
, options = {
json: isJSON
, body: payload || ''
};


if( method_exp.test(method) &amp;&amp; typeof request[_method] !== 'function' ) {
const t = cache.get(id);
t &amp;&amp; clearTimeout(t.timer);
cache.failure(id, err);
debug('unable to execute http transport', method, id);
return;
class Http extends Transport {
constructor(options) {
super(options)
}

debug('executing http transport %s', id, method);
request[_method](url, options, (err, res, body) => {
if(err){
debug('timer err', err);
return cache.failure(id, err);
exec( method, url, payload, id, cache ) {
const isJSON = typeof payload === 'object';
const _method = method.toLowerCase();
const options = {
json: isJSON
, body: payload || ''
}
if(res.statusCode > 299 ){
debug('timer fail', res.statusCode, body);
const error = new Error(STATUS_CODES[res.statusCode]);
error.code = res.statusCode = res.statusCode;
console.error(error, body);
return cache.failure(id, error);

if( method_exp.test(method) &amp;&amp; typeof request[_method] !== 'function' ) {
const pending = cache.get(id);
pending &amp;&amp; clearTimeout(pending.timer);
cache.failure(id, err);
debug('unable to execute http transport', method, id);
return;
}

debug('timer sucess');
return cache.success(id);
});
debug('executing http transport %s', id, method);
request[_method](url, options, (err, res, body) => {
if(err){
debug('timer err', err);
return cache.failure(id, err);
}
if(res.statusCode > 299 ){
debug('timer fail', res.statusCode, body);
const error = new Error(STATUS_CODES[res.statusCode]);
error.code = res.statusCode = res.statusCode;
console.error(error, body);
return cache.failure(id, error);
}

debug('timer sucess');
return cache.success(id);
});
}

get [Symbol.toStringTag]() {
return 'SkyringHttpTransport';
}
};

module.exports = Http
</pre>
</article>
</section>
Expand Down Expand Up @@ -200,7 +213,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>

on 2019-05-05T09:24:25-05:00
on 2019-05-11T22:48:54-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
Loading

0 comments on commit a9c3afb

Please sign in to comment.