Periodic scheduling

How to use meya.schedule to trigger periodic flows.

Meya provides a manage periodic scheduler via a built-in flow called meya.schedule. This allows your bot execute any flow of your choice on a pre-defined schedule. You can either schedule using cron syntax or the more simple period syntax:

  1. cron: 0 9 * * mon-fri will execute at 9am, Monday to Friday
  2. period: minutes, interval: 15 will execute every 15 minutes
states:
    intro:
        component: meya.text
        properties:
            text: "Great! I'll send you something nice every minute for the next hour (or until you say 'stop')"
    start:
        flow: meya.schedule
        data:
            tag: affirmation
            flow: nice
            period: minutes
            interval: 1
            max_count: 60

This affirmation example will trigger the nice flow every minute for an hour

There are many ways to configure meya.schedule.

Features

  1. cron or period based scheduling
  2. preventing duplicate flows from being invoked per user using tag
  3. auto-restarting on failure
  4. allow the user to unsubscribe from existing schedules using meya.schedule_stop
  5. limiting the total number of occurences
  6. rate limiting the executing loop, and terminating out of bounds schedules
  7. runs any flow that your bot has access to
  8. transparency and control on running schedules using the Meya platform tools
  9. pystache syntax for reading in data from your datastore flow, user, bot scope
flow: meya.schedule
data:
		# [required]
    flow: flow_name
    # pass data to the flow
    data: data needed for the flow
    # cron schedule. either `cron` or `period` are required
    cron: */5 * * * *
    # one of seconds, minutes, hours, weeks, months, years
    period: minutes
    # applies to period. how often to run. default 1 [optional]
    interval: 5
    # for stopping and preventing dupes [optional]
    tag: tag_name
    # max number of loops [optional]
    max_count: 100
    # base time to calculate first run [optional] default `now`
    base: 1465224764
    # the timezone to apply for cron jobs [optional] default `UTC`
    timezone: Canada/Eastern
    # where to read the timezone [optional]. Ignored if timezone is set
    timezone_scope: user

meya.schedule is actually a built-in flow that is made publicly available for all bot accounts. It's underlying architecture looks like this:

0

How the meya.schedule flow works under the hood

📘

Tip!

If you want to use the same underlying delay component for more advanced delays that simple relative/absolute delay, you can use the meya.delay component that is used by meya.schedule