Moogsoft Docs

Scheduler Moolet

You can schedule jobs at regular intervals by editing the $MOOGSOFT_HOME/config/moolets/scheduler.conf configuration file:

# The Scheduler is used to run scheduled jobs at regular
# intervals throughout the lifetime of moog_farmd. Only this
# moolet, which cannot subscribe to the MooMS bus and
# listen to events, is allowed to submit scheduled jobs.
# To start up successfully it must have the name and threads
# values set to "Scheduler" and 1 respectively.
        name                    : "Scheduler",
        classname               : "CScheduler",
        run_on_startup          : false,
        metric_path_moolet      : false,
        moobot                  : "Scheduling.js",
        threads                 : 1

To load the scheduler module:

var scheduler   =MooBot.loadModule('Scheduler');

Run jobs using, for example:

// A job that fails and does not restart.
scheduler.scheduleJob(this, "knockOnce", 5, 5, false);

This calls a method in the same js file called knockOnce:

function knockOnce()
    logger.warning("Knock knock");
    throw new Error("Failed to knock.");

The scheduledJob method has two possible parameter sets:

  • scheduleJob(this, functionName, start_delay , interval );

  • scheduleJob(this, functionName, start_delay, interval, true | false) ;




always this


the name of the function to call to run the job


is the delay from starting farmd to the first run (in seconds)


the interval between runs (in seconds)


decides whether the job will run again if it failed previously

Scheduling Frequency

When executing multiple jobs we recommend that you try and offset potential workload, by for example staggering the initial run of multiple jobs a few seconds apart or scheduling jobs at slightly offset frequencies.

  1. Must be single threaded.

  2. Only one per Moogfarmd process.

  3. Has to be called Scheduler.

  4. Use a Moobot module function as a scheduled job - which involves some rarer JavaScript as the scheduler won’t recognise function names from modules (it can’t find them)

    For example, in your scheduler moobot you might have:

    var autoClose=new AutoClose();
    // Bind the module function locally to the module function.
    var autoCloseAlertFunction = autoClose.closeAgedAlerts.bind(autoClose);
    // Schedule execution
    scheduler.scheduleJob(this, "autoCloseAlertFunction" , 60, autoCloseAlertFrequency , true);