Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
For this document, we will review how to leverage Qlik Sense Enterprise SaaS' open APIs to build advanced reload schedules.
Qlik Sense Enterprise SaaS implements reload schedules based on the RFC 5545 specification which is commonly known as rrule. The GUI presents a common subset of possible schedules with GUI-based options including hourly, daily, weekly, monthly, and yearly.
Qlik Sense Enterprise SaaS additionally exposes scheduling based on IANA Time Zone Database names. While this guide is written with a timeZone parameter set as America/New_York, refer to further documentation on additional permitted options.
This guide will use qlik-cli to abstract the RESTful API requests to build the reload task. There are additional parameters exposed in the qlik reload-task create command (e.g. partial reloads). Refer to qlik-cli's documentation for further guidance. For integrations where interaction occurs outside of qlik-cli, an example body of a reload task creation is as follows:
{
"appId": "58f563b6-ccda-45b0-926c-e2992ca8b470",
"recurrence": [
"RRULE:FREQ=MINUTELY;INTERVAL=15"
],
"startDateTime": "2022-03-23T00:00:00",
"timeZone": "America/New_York",
"type": "scheduled_reload"
}
This guide was written for use with the Windows PowerShell program. While PowerShell can be run on non Windows systems, use of bash techniques for parsing json (e.g. jq) is possible but not covered in this guide.
Reload a specific app every 15 minutes
# Specify the appId
$appId = '<myAppId>'
# Define the rrule
$schema = 'RRULE:FREQ=MINUTELY;INTERVAL=15'
$startDate = ((Get-Date)).ToString("yyyy-MM-ddT00:00:00") # Get the current date and convert to required format
# Get the app's reload tasks
$reloadTask = qlik reload-task ls --appId $($appId) | ConvertFrom-Json
# Delete the associated reload task, if present
if($reloadTask.data.Length -gt 0) {
$null = qlik reload-task rm $($reloadTask.data.id)
}
# Create the task
$null = qlik reload-task create --appId $appId --recurrence $schema --startDateTime $startDate --timeZone "America/New_York" --type "scheduled_reload"
Reload a specific app every hour on Thursday
# Specify the appId
$appId = '<myAppId>'
# Define the rrule
$schema = 'RRULE:FREQ=HOURLY;INTERVAL=1;BYDAY=TH'
$startDate = ((Get-Date)).ToString("yyyy-MM-ddT00:00:00") # Get the current date and convert to required format
# Get the app's reload tasks
$reloadTask = qlik reload-task ls --appId $($appId) | ConvertFrom-Json
# Delete the associated reload task, if present
if($reloadTask.data.Length -gt 0) {
$null = qlik reload-task rm $($reloadTask.data.id)
}
# Create the task
$null = qlik reload-task create --appId $appId --recurrence $schema --startDateTime $startDate --timeZone "America/New_York" --type "scheduled_reload"
Reload a specific app on the 2nd Monday of the month
# Specify the appId
$appId = '<myAppId>'
# Define the rrule
$schema = 'RRULE:FREQ=MONTHLY;WKST=MO;BYDAY=MO;BYSETPOS=2'
$startDate = ((Get-Date)).ToString("yyyy-MM-ddT00:00:00") # Get the current date and convert to required format
# Get the app's reload tasks
$reloadTask = qlik reload-task ls --appId $($appId) | ConvertFrom-Json
# Delete the associated reload task, if present
if($reloadTask.data.Length -gt 0) {
$null = qlik reload-task rm $($reloadTask.data.id)
}
# Create the task
$null = qlik reload-task create --appId $appId --recurrence $schema --startDateTime $startDate --timeZone "America/New_York" --type "scheduled_reload"
Note that when you create a reload task, you will have to encode the --recurrence argument in a way so that it starts and closes with a \" (backslash-doublequote). Every shell language will have its own way of encoding, for example this does it in *CMD* (Windows Command Prompt):
qlik reload-task create --appId "94782545-ae29-49e9-8b4b-41b3ac58dfc2" --recurrence \^"RRULE:FREQ=DAILY;INTERVAL=1;BYHOUR=0,2,4,6,8,10,12,14,16,18,20,22;BYMINUTE=0;BYSECOND=0\^" --timeZone "Europe/Zurich"
This will do the trick in *PowerShell* (in one line, without going via a variable definition as shown above):
.\qlik.exe reload-task create --appId 5cdefe35-91f1-4100-9524-73edb0d24247 --recurrence "\`"RRULE:FREQ=DAILY;INTERVAL=1;BYHOUR=0,2,4,6,8,10,12,14,16,18,20,22;BYMINUTE=0;BYSECOND=0\`"" --timeZone "Europe/Zurich"
@Levi_Turner I am currently working on a script similar to yours. It works perfectly, but as soon as I add another day in the BYDAY part of the RRULE I always get one of the following errors:
"errors": [
{
"code": "TASKS-001",
"title": "Invalid request.",
"detail": "chronos job request invalid: SCHED-400301: Scheduler API error (Invalid empty RRule)"
}
]
"errors": [
{
"code": "TASKS-001",
"title": "Invalid request.",
"detail": "invalid recurrence: bad format TU"
}
]
My RRULE looks like this:
$schema = 'RRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,TU;BYHOUR=7;BYMINUTE=25;BYSECOND=0'
As per RFC 5545 it should work with comma-seperated values.
When I set it manually in Qlik Cloud, or via "qlik reload-task edit ..." it works.
Do you have a working solution that would work in your example here?
Thanks a lot
@Benno : Ahh yes. You didn't specify whether you are using PowerShell 5 (the default on most Windows OSs) or PowerShell 7, but these approaches work for me:
PowerShell 5:
$schema = "RRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,TU;BYHOUR=7;BYMINUTE=25;BYSECOND=0"
qlik reload-task create --appId $appId --recurrence """""""$schema""""""" --startDateTime $startDate --timeZone "America/New_York" --type "scheduled_reload"
PowerShell 7:
$schema = "RRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,TU;BYHOUR=7;BYMINUTE=25;BYSECOND=0"
qlik reload-task create --appId $appId --recurrence "`"$schema`"" --startDateTime $startDate --timeZone "America/New_York" --type "scheduled_reload"
I need both. Thanks a lot for your help. I would have never guessed this solution