Schedule Condition
Overviewβ
The Schedule Condition allows you to schedule your own automations within Pia on a schedule that you define. For example, you may schedule an automation to run every Monday at 9am, or every 15 minutes.
The Schedule Condition can be selected in the Conditions menu of the Package Editor:
In this example, the below package will output "Hello World" (which is visible via the Live Packages View) every 15 minutes:
conditions:
- name: 'schedule'
cron: '0 15 * * * *'
steps:
- task: inline_powershell
inputs:
script: |
Write-Host "Hello World"
Condition Behaviorβ
The Schedule Condition will execute on the schedule provided by you in the "cron expression" input property (refer to details under input properties below).
Notes:
- You may scheduled package may execute up to 60 times in one minute.
- Scheduled packages are not bound to a ticket, so you will not be able to interact with the Pia Chatbot (such as by using the chat_interaction activity).
- The Schedule Condition is only active in live mode, not in sandbox mode. To test your package in sandbox mode, you will need to use the "Test Execute" feature or temporarily add a chat_interaction condition for use via the chatbot.
- Schedules execute with an accuracy of within a 100ms of the target time.
- Schedules will execute on the timezone specified in your tenant settings screen.
Combining Schedule Condition with Client Filter Condition
The Schedule Condition can be combined with the Client Filter condition to give the context of one or more clients. In practice, this means that if you specify a Client Filter condition targeting multiple clients; each time the schedule is triggered, multiple executions of a package will be initiated.
Scheduled packages with a Client Filter condition will be bound to a client. This means that you can access contextual variables for the client_id during execution. The main purpose of using the Client Filter condition with the Schedule condition is to schedule a package "on a per client basis".
You may want to schedule a report for a backup product on a nightly basis for each client which is tagged with "Backup-Product-A". The example below shows how you would do this:
conditions:
- name: 'schedule'
cron: '0 0 23 * * *'
- name: 'client_filter'
optMode: 'OptOut'
tags: 'Backup-Product-A'
category: 'Backup'
steps:
- task: inline_powershell
inputs:
client_id: $Ctx_Client_Id
script: |
Write-Host "Send an email to the partner $client_id"
Input Propertiesβ
Use properties to modify the behavior of the condition.
Property Name: cron
Property Required: Yes
Property Description: A cron expression to define the schedule interval for executing your package. Cron expressions must contain 6 fields, refer to the diagram below for how to define your expression.
Pia uses Cronos for cron expression handling: https://github.com/HangfireIO/Cronos
Allowed values Allowed special characters Comment
ββββββββββββββ second (optional) 0-59 * , - /
β ββββββββββββββ minute 0-59 * , - /
β β ββββββββββββββ hour 0-23 * , - /
β β β ββββββββββββββ day of month 1-31 * , - / L W ?
β β β β ββββββββββββββ month 1-12 or JAN-DEC * , - /
β β β β β ββββββββββββββ day of week 0-6 or SUN-SAT * , - / # L ? Both 0 and 7 means SUN
β β β β β β
* * * * * *
Example expressions:
Cron Expression | Meaning |
---|---|
0 /5 * * * | Every 5 minutes |
0 1 * * * * | At the first minute of every hour |
0 0 16 * * * | At 4pm every day |
0 0 19 * * MON-FRI | 7pm every weekday |
Property Name: mode
Property Required: No
Property Description: Behavior in the event that a schedule time is missed. This only applies if a system outage were to occur (such as during a Pia update).
Property Default: RunResume
Property Options:
Option | Meaning |
---|---|
RunResume | Will resume execution and ignore historical schedules which may have been missed |
RunOneMissed | Will run the immediate last schedule which was missed (if any) |
RunAllMissed | Will run all schedules which were missed (if any) |