Smithable websitedocsGitHubTry it
Menu

Things that happen on a clock

Some things should happen at a time rather than when someone presses a button: a reminder the day before a class, an invoice marked overdue a week after it was due, a post published when its time comes, a digest every Monday morning. A timer says so in smithable.yml. The app raises it itself, on time, and it is versioned, shown in What it does and undone like any other change.

A timer does one of two things: it runs an action, or it only raises its event, for an outgoing entry to send a mail or make a call. Sending is always outgoing's.

1. At a date of each record

timers:
  remind:
    on: Booking
    at: 1 day before session.startsAt   # a date or date-time of the record, or one reference away
    where: { status: confirmed }        # optional: only the records that fit

outgoing:
  reminder:
    when: remind                        # the timer's name, as an action's
    to: mail
    recipient: owner

2. On a clock

timers:
  weeklyDigest:
    every: monday        # day, weekday, week, month, or a weekday's name
    at: "08:00"          # in the app's time zone
    run: sendDigest      # a custom action, run once
  payroll:
    cron: "0 6 25 * *"   # what every cannot say
    run: closePayroll

What a timer may do

A timer runs as the app, with no one signed in: no role's rights apply, as for calls in. The app's summary says each timer in one sentence ("Every Monday at 08:00: runs Send digest").

A timer follows a field that is renamed, and a field or an action it uses cannot be removed while it is there. A timer that an outgoing entry listens to cannot be removed until the entry goes.

From the command line

$ smithable op addTimer remind --on Booking --at "1 day before session.startsAt" --where status=confirmed
$ smithable op addTimer weeklyDigest --every monday --at 08:00 --run sendDigest
$ smithable op setTimer remind --where none
$ smithable op removeTimer remind

setTimer changes the parts it names: a new time replaces the old one, and none takes where, run or on away. The spec reference has every rule.