Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
pschmidt1973
Partner - Contributor II
Partner - Contributor II

How to trigger tasks using the QRS API based on tags

We have a multi-tenanted environment and need to start customer tasks on a daily basis. By way of an example, we have 33 customers that each have their own reload task. The data is extracted from a customer's onsite source on a daily basis and loaded into a multi-tenanted Data Warehouse.

The Qlik Sense tasks run based on a daily schedule at 8 am each morning, this is not ideal as the Qlik Sense tasks do not know when the Data Warehouse has finished loading. Ideally, I would like to trigger each task via the QRS API once the DWH has completed.

Each customer reload task has been a tagged with the source system the data relates to, for example, the 33 customers have a tag of "HPOS" against each reload task.

I would like to be able to use the QRS API to do two things:

1. Filter a list of reload tasks based on a tag, in the above example "HPOS".

2. Start the reload tasks based on the filtered list.

Any suggestions are welcome.

9 Replies
ToniKautto
Employee
Employee

I would suggest that you explore the Qlik CLI (GitHub - ahaydon/Qlik-Cli: Qlik Sense Cmdlet for PowerShell) which allows you to utilize the Qlik Sense Repository Service (QRS) APIs through PowerShell.

Get-QlikTask -full returns a list of all tasks, including the tag values.


Get-QlikTask -full | where {$_.tags.name -eq "HPOS"}) pipes the task list into a filter, to only keep the required tags.


(Get-QlikTask -full | where {$_.tags.name -eq "HPOS"}).id limits the filtered task list to only the task ID values.

(Get-QlikTask -full | where {$_.tags.name -eq "HPOS"}).id | foreach { Start-QlikTask $_ } as a final step pipes each filtered task ID to being started.

k21
Contributor II
Contributor II

Hello, 

Is it possible to filter the list of reload tasks based on a specific pattern on the name ? Let's say, the tasks that the name contains a specific caracteres exmpl : Names contains "test" ? 

If so, please let me know how to implement such a thing .. 

stefanstoichev123

@k21  have a look at the Relational operators section at the documentation page

In your case you can filter the tasks by using:

name -so "test"

this will filter all entities that are having test in their name

 

stefanstoichev123_0-1688987112071.png

Stefan

k21
Contributor II
Contributor II

Okay, thanks for ur quick reply, 

and is it possible to extract the id of this task, using qlik qrs options ? I was testing this: 

/home/jenkins/.local/bin/qlik qrs reloadtask ls --filter "name so '$TaskNameDependency'" | jq -r '.[] | {id:.id}| .id'
 
But it is not working .. I am not sure what's the issue; 
stefanstoichev123

Probably check the content of the TaskNameDependency variable? or the context is wrong and such tasks do not exists on the cluster you are quering?

The same command returns the task ids for me.

stefanstoichev123_0-1688999954811.png

 

Stefan

k21
Contributor II
Contributor II

Finally it is working, Thanks a lottttttttttt! 

I still have one qst;

I m creating a task_2 that depends from other task_1 but task_2 is being created but it does not include the trigger in qlik UI, how to fix this, any ideas plz ? 

stefanstoichev123

Possible to share some code?

 

Stefan

k21
Contributor II
Contributor II

Sorry for the late response, It takes me a bit of time to figure this out ..  I think i am able now to create tasks that depend from other tasks .. I created a composite rule : 

    compositeRule=${compositeRule::-1}
    compositeEvent='{"timeConstraint":{"days":0,"hours":0,"minutes":360,"seconds":0},"compositeRules":['$compositeRule'],"name":"EventTrig","enabled":true,"eventType":1}'

 and then I am using a post curl api to create the task with this compositeRule ..

curl -X POST "$serverUrl/create?xrfkey=$id" \
                    -H "x-qlik-xrfkey: $id" \
                    -H "Content-type: application/json" \
                    -H "Authorization: Bearer ${token}" \
                    -d '{"task": { "app":  { "id":  "'$idapplication'" }, "enabled": true , "schemaPath": "ReloadTask" ,  "name": "'"$TaskName"'"}, "compositeEvents": ['$compositeEvent'] }'



Now I am struggling to create a compositeRule for a Daily and weekly tasks .. I think I should be able to create a curl post command with a different composite,  but i am not able to define the compositeRule for daily or weekly  tasks  .. I hope it is clear  .. 

This is my curl post: 

             response=$( curl -X POST "$serverUrl/create?xrfkey=$id" \
                    -H "x-qlik-xrfkey: $id" \
                    -H "Content-type: application/json" \
                    -H "Authorization: Bearer ${token}" \ 
-d '{"task": { "app": { "id": "'$idapplication'" }, "enabled": true , "schemaPath": "ReloadTask" , "name": "'"$TaskName"'" }, "schemaEvents":[{ "name": "'$TaskFrequence'" ,"enabled":true, "eventType":0, "timeZone":"Europe/Paris","daylightSavingTime":0,"startDate": "'$startDate'","expirationDate":"9999-01-01T00:00:00.000", "schemaFilterDescription": ["'"$schemaFilterDescription"'"] , "incrementDescription": "'"$incrementDescription"'" , "incrementOption": "'$incrementOption'"}] }' )  

 

k21
Contributor II
Contributor II

I think I know what's the error, apprently it is related to my config, can anyone please check this for me ? 


        if [ "$TaskFrequence" == "Daily" ]; then
            schemaFilterDescription="* * - * * * * *"
            incrementDescription="0 0 1 0"
            incrementOption="2"
        elif  [ "$TaskFrequence" == "Weekly" ]; then
            schemaFilterDescription="* * - $WeekDay 1 * * *"
            incrementDescription="0 0 1 0"
            incrementOption="3"
        elif  [ "$TaskFrequence" == "Monthly" ]; then
            schemaFilterDescription="* * - * * $DayOfMonth * *"
            incrementDescription="0 0 1 0"
            incrementOption="4"