Relatude Help

36.1 Jobs

The database registers these jobs itself:

Job What it does Argument
backup Writes a backup: a copy of the log, or of the current state when Truncate backups is on keep: never deleted by delete-old-backups. truncate or copy overrides the setting. Combine: keep,truncate
delete-old-backups Deletes the backups the retention settings do not keep. Backups marked keep stay none
truncate-log Rewrites the log as the current state, giving up the history and the option to revert into it. Skipped while a revert window is open delete-old: deletes the old log file afterwards
delete-old-log-files Deletes the log files that truncations left behind none
save-state Writes the state snapshot and the index states, so the next open does not replay the log none
purge-caches Halves the node and set caches and frees the memory none
reindex-text Queues every node of the text-indexed types for text indexing again none
delete-unreferenced-files Deletes the files no node refers to, except those uploaded in the last 15 minutes count: only counts them

A built-in job given an argument it does not take fails its run and names the ones it takes, so a typo in a schedule does not go unnoticed.

Register your own jobs in OnStoreInit. It runs every time the database is set up, before it opens, so a schedule that names the job finds it from the first tick:

builder.AddRelatudeDB(options => {
    options.OnStoreInit = db => {
        db.Jobs.Add("send-digest", async ctx => {
            var sent = await Digest.SendAsync(db, ctx.Argument, ctx.CancellationToken);
            ctx.Report(sent + " mails sent"); // shown beside the run on the Scheduler page
        }, "Mails the daily digest to every subscriber", "Who gets it: all, or staff");
    };
});

The last two arguments describe the job and its argument on the Scheduler page. The job is handed a JobContext:

Member What it is
Argument The schedule's Argument, or the one given when the job was started by hand
CancellationToken Cancelled when the database closes or someone stops the run. Pass it on: a closing database waits only a few seconds
Report(message) One line on how it went, shown on the Scheduler page and written to the system log
Progress(percentage, text) Shown with the database's other activities while the job runs
ScheduleId, ScheduleName, DueUtc, Trigger Which schedule started it, for which time, and how: Schedule, Missed or Manual

A job that throws fails its run. The error is shown on the Scheduler page and logged, and the failed batch stays on the Tasks page for a day, where Queue again runs it again. To start a run from code, call db.Jobs.Run("send-digest", "staff"). It queues the run and returns at once.