Skip to content

Commit

Permalink
doc: updating docs
Browse files Browse the repository at this point in the history
  • Loading branch information
esatterwhite committed May 24, 2017
1 parent 46b4fd1 commit cf6b9b2
Show file tree
Hide file tree
Showing 38 changed files with 449 additions and 275 deletions.
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,38 @@ persists between starts. To enable full persistence and recovery, you must confi
persistent backend for `levelup`. [Leveldown](https://www.npmjs.com/package/leveldown) is installed by default.


```js
```bash
skyring run --storage:backend=leveldown --storage:path='/var/data/skyring'
```

# Custom Transports

Skyring ships with a single HTTP transport, but support custom transports. A `transport` is a named function
that can be executed when a timer triggers. To register a transport, you can pass an array of named functions, or
requireable paths to the skyring server constructor via via the `transports` option

```javascript
const path = require('path')
const Skyring = require('skyring')

function fizzbuz(method, uri, payload, id, timer_cache) {
...
}
const server = new Skyring({
transports: [
'my-transport-module'
, fizzbuz
, path.resolve(__dirname, '../transports/fake-transport')
]
})
```

The same can be achieved through CLI arguments or ENV vars via the `transport` key

```bash
transport=foobar,fizzbuz node index.js
```

```bash
node index --transport=foobar --transport=fizzbuz --transport=$PWD/../path/to/my-transport
```
20 changes: 18 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,23 @@ <h2>Create a timer</h2><h5><strong>POST <code>/timer</code></strong></h5><p><str
immediately load them back into memory. By default, the <a href="https://www.npmjs.com/package/memdown">memdown</a> backend is used, and wil not
persists between starts. To enable full persistence and recovery, you must configure skyring to use a
persistent backend for <code>levelup</code>. <a href="https://www.npmjs.com/package/leveldown">Leveldown</a> is installed by default.</p>
<pre class="prettyprint source lang-js"><code>skyring run --storage:backend=leveldown --storage:path='/var/data/skyring'</code></pre></article>
<pre class="prettyprint source lang-bash"><code>skyring run --storage:backend=leveldown --storage:path='/var/data/skyring'</code></pre><h1>Custom Transports</h1><p>Skyring ships with a single HTTP transport, but support custom transports. A <code>transport</code> is a named function
that can be executed when a timer triggers. To register a transport, you can pass an array of named functions, or
requireable paths to the skyring server constructor via via the <code>transports</code> option</p>
<pre class="prettyprint source lang-javascript"><code>const path = require('path')
const Skyring = require('skyring')

function fizzbuz(method, uri, payload, id, timer_cache) {
...
}
const server = new Skyring({
transports: [
'my-transport-module'
, fizzbuz
, path.resolve(__dirname, '../transports/fake-transport')
]
})</code></pre><p>The same can be achieved through CLI arguments or ENV vars via the <code>transport</code> key</p>
<pre class="prettyprint source lang-bash"><code>transport=foobar,fizzbuz node index.js</code></pre><pre class="prettyprint source lang-bash"><code>node index --transport=foobar --transport=fizzbuz --transport=$PWD/../path/to/my-transport</code></pre></article>
</section>


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

on 2017-04-30T22:01:03-05:00
on 2017-05-21T22:06:06-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
61 changes: 29 additions & 32 deletions docs/index.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,42 +83,38 @@ <h1 class="page-title">Source: index.js</h1>
* @requires skyring/lib/server
**/

const http = require('http')
, path = require('path')
, conf = require('keef')
;

if( require.main !== module ){
conf.defaults(require(path.join(__dirname, 'conf/index.json')))
module.exports = require('./lib/server');
return;
}


const Server = require('./lib/server')
const conf = require('./conf')
, Server = require('./lib/server')
, debug = require('debug')('skyring')
;

process.title = 'skyring';
process.chdir(__dirname);

const server = new Server();

module.exports = server;
module.exports = Server;

if( require.main === module ){
process.title = 'skyring';
process.chdir(__dirname);

const server = new Server();

server.load().listen(conf.get('PORT'),null, null, (err) => {
if(err) {
process.exitCode = 1;
console.error(err);
throw err;
}
debug('server listening');
});

function onSignal() {
server.close(()=>{
debug('shutting down');
});
}
process.once('SIGINT', onSignal);
process.once('SIGTERM', onSignal);
}

server.load().listen(conf.get('PORT'),null, null, (err) => {
if(err) return console.log(err) || process.exit(1)
debug('server listening')
});

function onSignal() {
server.close(()=>{
debug('shutting down')
process.statusCode = 0
})
}
process.once('SIGINT', onSignal);
process.once('SIGTERM', onSignal);


/**
Expand All @@ -137,6 +133,7 @@ <h1 class="page-title">Source: index.js</h1>
* @property {String[]} [options.storage.backend=memdown] a requireable module name, or absolute path to a leveldb compatible backend
* `leveldown` and `memdown` are installed by default
* @property {String} options.storage.path A directory path to a leveldb instance. One will be created if it doesn't already exist.
* @param {String[]|Function[]} [optsion.transport] an array of custom transport functions, or requireable paths that resolve to functions. All transport function must be named functions
* If the backend is memdown, this is optional and randomly generated per timer instance
**/
</pre>
Expand Down Expand Up @@ -184,7 +181,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-04-30T22:01:03-05:00
on 2017-05-21T22:06:06-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
10 changes: 5 additions & 5 deletions docs/lib_json.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ <h1 class="page-title">Source: lib/json.js</h1>
* @return {module:skyring/lib/json~Result}
**/
exports.parse = function parse(json) {
if (!json) return {error: null, value: {}}
if (!json) return {error: null, value: {}};
try {
return { error: null, value: JSON.parse(json) }
return { error: null, value: JSON.parse(json) };
} catch( e ) {
return {error: e, value: null}
return {error: e, value: null};
}
}
};

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

on 2017-04-30T22:01:03-05:00
on 2017-05-21T22:06:06-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
26 changes: 11 additions & 15 deletions docs/lib_nats.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,8 @@ <h1 class="page-title">Source: lib/nats.js</h1>
})
*/

const url = require('url')
, util = require('util')
, nats = require('nats')
, config = require('keef')
const nats = require('nats')
, config = require('../conf')
, debug = require('debug')('skyring:nats')
, nats_hosts = config.get('nats:hosts')
, csv_exp = /\s?,\s?/g;
Expand All @@ -108,13 +106,13 @@ <h1 class="page-title">Source: lib/nats.js</h1>
hosts:'nats-1.domain.com:4222,nats-2.domain.com:4223,localhost:4222'
})
**/
exports.createClient = createClient
exports.createClient = createClient;

Object.defineProperty(exports, 'client', {
get: function() {
return client || createClient()
return createClient();
}
})
});

function createClient(options) {
const hosts = (options &amp;&amp; options.hosts) || nats_hosts;
Expand All @@ -141,13 +139,13 @@ <h1 class="page-title">Source: lib/nats.js</h1>

client.on('reconnecting', () => {
debug('nats client reconnecting');
})
});

client.quit = (cb) => {
debug('closing nats', client.info.server_id)
debug('closing nats', client.info.server_id);
client.close();
client.once('disconnect', cb)
}
client.once('disconnect', cb);
};

return client;
}
Expand All @@ -162,9 +160,7 @@ <h1 class="page-title">Source: lib/nats.js</h1>
}

function parseItem(str) {
return str.indexOf('nats://') === 0
? str
: `nats://${str}`
return str.indexOf('nats://') === 0 ? str : `nats://${str}`;
}

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

on 2017-04-30T22:01:03-05:00
on 2017-05-21T22:06:06-05:00

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

0 comments on commit cf6b9b2

Please sign in to comment.