var log4js = require("log4js"),
    log = log4js.getLogger("megapis-worker"),
    handlebars = require("handlebars"),
    fs = require("fs"),
    moment = require("moment"),
    util = require("util");

var MegapisWorker = require("megapis-worker").MegapisWorker;

function Worker(config) {
    Worker.super_.call(this, config);
}
 
util.inherits(Worker, MegapisWorker);

exports.createWorker = function(config) {
    return new Worker(config);
};

Worker.prototype.getConfigKeys = function() {
    return ["output"];
};

Worker.prototype.run = function(callback) {
    var self = this;
    var config = this.config;
    var filename = "config/"+this.config.id+".hbs";
    var template = handlebars.compile(fs.readFileSync(filename, "utf-8"));
    //this.getAndDelete(config.id, function(err, values) {
    this.get(config.id, function(err, values) {
        log.debug("found "+values.length+" values for "+config.id);
        var html = template({
            "values": values,
            "createdDate": moment().format("ddd M/D h:mm a")
        });
        self.save([html], callback);
    });
};

@@ -745,10 +745,8 @@
     
-//
 this
@@ -794,24 +794,26 @@
 lues) %7B%0A    
+//
 this.get(con
@@ -912,16 +912,49 @@
 ig.id);%0A
+        if (values.length) %7B%0A    
         
@@ -987,16 +987,20 @@
         
+  
+  
 %22values%22
@@ -1009,16 +1009,20 @@
 values,%0A
+    
         
@@ -1078,24 +1078,28 @@
 a%22)%0A        
+    
 %7D);%0A        
@@ -1098,16 +1098,20 @@
         
+   
+ 
 self.sav
@@ -1131,16 +1131,67 @@
 lback);%0A
+        %7D else %7B%0A            callback();%0A        %7D%0A
     %7D);%0A

delete key after reading; check for empty