-
Notifications
You must be signed in to change notification settings - Fork 5
Micropilot #73
Micropilot #73
Changes from all commits
d0db489
b86d69c
3fcfb63
ddbb700
ca63f8e
6acd3bc
33d2cf4
6d50291
9a2261b
7b34a80
9645900
560f6be
e9990b4
c192357
22efa0e
195ca83
792fb80
279fac2
149165a
58f6771
98dafb1
880cfbc
ed8a8ac
b1957bc
7d406e9
0e69d58
8c962ba
7389408
a7a24aa
bcbd950
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
*.swp | ||
*~ | ||
packages/micropilot |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// This module encapsulates all the micropilot logic. Other modules should only | ||
// ever have to use monitor.record. | ||
|
||
const micropilot = require("micropilot"); | ||
const { storage } = require("simple-storage"); | ||
const myprefs = require("simple-prefs").prefs; | ||
|
||
// Our AWS box | ||
const UPLOAD_URL = "https://107.22.82.223"; | ||
// Upload every day in milliseconds | ||
const PULSE_INTERVAL = 24 * 60 * 60 * 1000; | ||
|
||
let monitor = micropilot.Micropilot("blushproof").start(); | ||
/** | ||
* A helper function to record time-stamped events. Times are modulo the | ||
* most recent hour. | ||
* @param eventName {string} The name of the event. | ||
* @return promise | ||
*/ | ||
//micropilot.Micropilot.prototype.recordEvent = function recordEvent(eventName) { | ||
exports.recordEvent = function recordEvent(eventName) { | ||
let d = new Date(); | ||
d.setMinutes(0); | ||
d.setSeconds(0); | ||
d.setMilliseconds(0); | ||
return monitor.record({timestamp: d.getTime() / 1000, event: eventName}); | ||
}; | ||
|
||
function uploadAndClear() { | ||
// We might lose events between when this.upload() returns and this.clear() | ||
return monitor.upload(UPLOAD_URL).then(monitor.clear); | ||
}; | ||
|
||
// Only start the Fuse to upload results if reporting is enabled | ||
if (myprefs.enable_reporting) { | ||
var f = micropilot.Fuse({ | ||
start: Date.now(), | ||
// Run forever | ||
duration: false, | ||
// Upload daily | ||
pulseinterval: PULSE_INTERVAL, | ||
pulsefn: uploadAndClear | ||
}).start(); | ||
} | ||
|
||
exports.monitor = monitor; | ||
const kEventNames = exports.kEvents = { | ||
ADD_BLUSHLIST: "add-blushlist", | ||
BLUSHY_QUERY: "blushy-query", | ||
BLUSHY_SITE: "blushy-site", | ||
FORGET_SITE: "forget-site", | ||
OPEN_NORMAL: "open-normal", | ||
OPEN_PRIVATE: "open-private", | ||
REMOVE_BLUSHLIST: "remove-blushlist", | ||
WHITELISTED_QUERY: "whitelisted-query", | ||
WHITELISTED_SITE: "whitelisted-site" | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,27 @@ | |
"description": "stop opening naughty sites accidentally", | ||
"author": "David Keeler <[email protected]>, Monica Chew <[email protected]>, Gregg Lind <[email protected]>", | ||
"license": "MPL 2.0", | ||
"version": "0.1" | ||
"version": "0.1", | ||
"dependencies": [ | ||
"micropilot" | ||
], | ||
"preferences": [ | ||
{ | ||
"type": "bool", | ||
"title": "Enable debug messages", | ||
"name": "micropilotlog", | ||
"value": true | ||
}, | ||
{ | ||
"type": "bool", | ||
"title": "Report metrics", | ||
"name": "enable_reporting", | ||
"value": false | ||
} | ||
], | ||
"volo": { | ||
"dependencies": { | ||
"packages/micropilot": "github:gregglind/micropilot/v0.8" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was expecting this to automatically fetch micropilot for me. Too much to ask, or do I not have volo set up correctly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think, but am not sure, that this means that if we use volo to install blushproof itself then volo will fetch packages/micropilot, e.g. volo create myaddon micropilot-template However, I'm not sure how/if we can take advantage of that in the development cycle. @gregglind, any clues? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't seem to be supported: volojs/volo#149 Seems like the intended workflow is to manually call volo add -f when you want to update the dependency. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, figure out workflow by reading bugs: volojs/volo#22 @jrburke, is the expected workflow to contribute to a git-managed codebase with volo dependencies to git clone myproject ? |
||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This didn't work