Files
meteor/tools/run-updater.js
Sashko Stubailo e7167e5257 Factor out almost all fs. and path. calls in the tool
This will be useful when we want to be smart with windows file paths later
Also, all of the file calls are asynchronous with fibers now, which comes with
many benefits.

This is a combination of 23 commits. Original messages:
Wrap a large number of fs calls inside files.*

Convert a few more fs calls to files.*

More moving fs.* to files

Implement read/write streams and open/read/close

Get rid of fs from auth.js

Remove fs and unused imports from catalog-local and catalog-remote

Remove unused imports from catalog.js

Replace a whole lot of fs calls

Fix error

Migrate a lot more fs. calls to files.

Add a temporary symlink method

Convert old test to files.*

Use files.pathX instead of path.x everywhere

Replace path.x to files.pathX in tests

Small fixes to files.js and one rename

Make cleanup run in a fiber

Make wrapping functions take function name in case we need it

Add some timeouts and stuff to HCP tests

wrapFsFunc also makes a sync version of the function

Sometimes you just don't want to yield!

Make sure JsImage readFromDisk doesn't yield

Remove unused imports from npm test

Change order of test now that some things don't yield

Fix missing files import, and add a debug error printout
2014-12-15 15:32:06 -08:00

62 lines
1.6 KiB
JavaScript

var _ = require('underscore');
var Fiber = require('fibers');
var fiberHelpers = require('./fiber-helpers.js');
var Console = require("./console.js").Console;
var Updater = function () {
var self = this;
self.timer = null;
};
// XXX make it take a runLog?
// XXX need to deal with updater writing messages (bypassing old
// stdout interception.. maybe it should be global after all..)
_.extend(Updater.prototype, {
start: function () {
var self = this;
if (self.timer)
throw new Error("already running?");
// Check every 3 hours. (Should not share buildmessage state with
// the main fiber.)
self.timer = setInterval(fiberHelpers.inBareFiber(function () {
self._check();
}), 3 * 60 * 60 * 1000);
// Also start a check now, but don't block on it. (This should
// not share buildmessage state with the main fiber.)
new Fiber(function () {
self._check();
}).run();
},
_check: function () {
var self = this;
var updater = require('./updater.js');
try {
updater.tryToDownloadUpdate({showBanner: true});
} catch (e) {
// oh well, this was the background. Only show errors if we are in debug
// mode.
Console.debug("Error inside updater.");
Console.debug(e.stack);
return;
}
},
// Returns immediately. However if an update check is currently
// running it will complete in the background. Idempotent.
stop: function () {
var self = this;
if (self.timer)
return;
clearInterval(self.timer);
self.timer = null;
}
});
exports.Updater = Updater;