UNPKG

royal-thing

Version:

A process that restarts the local registrant when needed

42 lines (36 loc) 1.1 kB
// Generated by CoffeeScript 2.4.1 (function() { var URL, debug, pkg; module.exports = async function(host, db) { var info, local_uri, save, update_seq; debug('Start', host); local_uri = new URL(`_local/royal-${host}`, db.uri + '/'); save = async function(seq) { var doc; debug('save', {seq}); doc = (await db.agent.get(local_uri).accept('json').then(function({body}) { return body; }).catch(function() { return {}; })); if (seq == null) { return doc; } doc.update_seq = seq; return (await db.agent.put(local_uri).send(doc)); }; // On first run, retrieve the last `update_seq` and save it. ({update_seq} = (await save())); if (update_seq == null) { debug('install: save current update_seq'); info = (await db.info()); await save(info.update_seq); } else { debug('Re-using', {update_seq}); } return {save}; }; ({URL} = require('url')); pkg = require('./package.json'); debug = (require('debug'))(`${pkg.name}:install:trace`); }).call(this);