gregglind / micropilot

Lightweight event monitoring and observation in Firefox addons.
http://gregglind.github.com/micropilot/
4 stars 2 forks source link

recurrent upload should be better supported #17

Closed gregglind closed 11 years ago

gregglind commented 11 years ago

possible ways:

// daily upload.
// TBD (glind) replace with fuse?  bad for small intervals
/*
if (! storage.lastupload) storage.lastupload = Date.now(); // tied to addon
require("timers").setInterval(function(){
    if (Date.now() - storage.lastupload > UPLOADINTERVAL) {
        storage.lastupload = Date.now();
        mtp.upload(URL);
    }
}, UPLOADINTERVAL)
*/
/* Fuse based recurrent upload*/
let uploadrecur= function(study,interval){
  if (! storage.lastupload) storage.lastupload = Date.now(); // tied to addon
  Fuse({start: storage.lastupload,duration:DURATION}).then(
    function(){
      storage.lastupload = Date.now();
      mtp.upload(URL).then(function(response){
        micropilot.microlog("micropilot-upload-response", response.text);
        // TODO, args for clear()
      });
      uploadrecur(UPLOADINTERVAL); // call it again.
    })
};
ilanasegall commented 11 years ago

I like the fuse-based approach, as seen in ctp-micropilot. Another approach: have a repeat_every function that takes an action (in this case, upload), as we may want to do other things once per whatever (ping, display a notification, whatever)

lifetime(whatever).then(fn {ezupload()}) => repeat_every(whatever).(fn {ezupload()})

gregglind commented 11 years ago

punt to micropilot-template, see #22