var co = require('co');

var Agenda = require('agenda');

class BBIJob {

    /**
     * @abstract
     */
    constructor() {
        if (!new.target) throw "BBIJob() must be called with new";

        if (new.target === BBIJob) {
            throw new TypeError("Cannot construct abstract instances directly");
        }

        this.config = null;

        /** @type {Agenda} */
        if(!(BBIJob.runner instanceof Agenda)) {
            BBIJob.runner = null;
            BBIJob.ready = false;
        }

        process.on('SIGTERM', this.graceful);
        process.on('SIGINT' , this.graceful);
    }

    graceful() {
        this.stop();
    }

    * initialize(config) {
        this.config = config;

        /** @type {Agenda} */
        if(!(BBIJob.runner instanceof Agenda)) {
            BBIJob.runner = new Agenda({
                db: {
                    address: this.config.agenda.url,
                    collection: this.config.agenda.collection
                }
            });
            BBIJob.runner.on('ready', function() {
                BBIJob.ready = true;
            });
        } else {

        }
    }

    *start() {
        this.runner.start();
    }

    *stop() {
        if(BBIJob.ready === true) {
            BBIJob.ready = false;
            this.runner.stop();
        }
}

    add(name, options, func) {
        this.runner.define(name, options, func);
    }


}
@@ -1001,130 +1001,8 @@
 %7D);%0A
-            BBIJob.runner.on('ready', function() %7B%0A                BBIJob.ready = true;%0A            %7D);%0A        %7D else %7B%0A%0A
     
@@ -1089,16 +1089,17 @@
       if
+ 
 (BBIJob.
@@ -1192,16 +1192,20 @@
       %7D%0A
+    
 %7D%0A%0A    a
@@ -1208,24 +1208,31 @@
    add(name,
+ every,
  options, fu
@@ -1290,13 +1290,52 @@
 c);%0A    
+    this.runner.every(every, name);%0A    
 %7D
-%0A
 %0A%0A%7D

Work in progress... #3