Skip to content

Scheduler

Sébastien Blin edited this page Nov 7, 2020 · 3 revisions

Goal

For some use cases, RORI must do periodic tasks. For parsing news, calendars, alarms, etc. This is why a Scheduler is present and available for modules to be able to schedule tasks.

How it works when running

When initializing, RORI will parse the related table in the database and drop tasks for invalid modules, devices or if it can't generate a good task. The scheduler will also launch a thread which will execute pending jobs.

When running modules can add/update/delete tasks via the API.

The scheduler will execute tasks with the interval described by at/seconds/minutes/hours/days/repeat. And will execute the module given by the "module" column with "parameter" used to craft the interaction.

Related table in the database

This is the table used by the scheduler:

CREATE TABLE IF NOT EXISTS scheduler (
    id          INTEGER PRIMARY KEY AUTOINCREMENT,
    module      INTEGER,
    parameter   TEXT,
    at          TEXT,
    seconds     INTEGER,
    minutes     INTEGER,
    hours       INTEGER,
    days        STRING,
    repeat      INTEGER,
    FOREIGN KEY (module) REFERENCES modules(id)
)

Note: parameter is a serialized JSON used to craft the interaction given to the module to exec. To find the user related to this task, it must at least contains two keys: username, ring_id or the scheduler will drop the task as invalid.

Note: days supports integers or "Monday" to "Sunday" and "Weekday"

Example

https://github.com/AmarOk1412/rori_modules/tree/master/command/feed is a module that uses the Scheduler

Clone this wiki locally