Qlik Community

Qlik Sense Documents & Videos

Documents & videos about Qlik Sense.

Announcements
See why Qlik is recognized as a Leader for the 10th year in a row – and discover how Qlik can help put your business in the lead. Get Report

Task Chaining with NPrinting - adding status check

Employee
Employee

Task Chaining with NPrinting - adding status check

In the previously posted document a number of samples including how to create a QLik script and task that triggers an NPrinting task.

Task chaining from QlikView to NPrinting17 and Qlik Sense to NPrinting17

While this works perfectly well, the status of the Qlik Sense task in QMC is reflective on whether the QLik script code completed without error.  If the script was able to successfully submit the publish task request, it will say success. But what if the NPrinting task that was triggered ran for an hour and then errored out ?  Well, the reports would not be delivered and the Qlik Sense tasks would have still said success.

A trick to resolve this is to add a 'status check' into the same Qlik script that loops on an interval to see when the task completes. In the attached i added a configurable timeout, interval as well as a few other configuration variables to make the script more re-usable . Things like the NP server name, whether you are using http or https etc...

For now it only checks for a few of the possible status' and manually throws an error if things fail.

Below you will see the additional code in the 'Set Variables' section as well as the 'Check Status" section that make this possible.

THis way, the QLik task won't complete until

1. it hits the timeout you set

2. it succeeds

3. it fails

Whats not in there is 'killing' the NP task if its still running past the timeout. That can be cleaned up to using a 'patch' request on the NP task execution .  I'll do that next time !

-jonny

capture variables.PNG

capture vstatus check.PNG

Attachments
Comments
Partner
Partner

I added some logic for which Nprinting task to trigger. Based on what name you have on the app (one for each Nprinting task), you can trigger the task that way.

Below script searches for "NPTrigg_" in the name, then finds out the Task name to trigger.

//this fetches what NPrinting document to run

if findoneof(replace(DocumentTitle(), 'NPTrigg_', '#'), '#') > 0 then

LET vL_GenNPName = subfield(DocumentTitle(), 'NPTrigg_', '-1');

   

trace 'found document title ' & $(vL_GenNPName);

elseif findoneof(replace(DocumentTitle(), 'NPTrigg_', '#'), '#') = 0 then

trace 'I couldnt find any document title';

throw an error;

end if

Also in your script, sometimes it takes a few seconds for the script to start, meaning "Assigned" can be interpreted as an error. I changed the script on last page to:

if  vTaskExecutionStatus <> 'Enqueued' and vTaskExecutionStatus <> 'Running' and vTaskExecutionStatus <> 'Assigned' and vTaskExecutionStatus <> 'WaitingForRetry'  then

See https://help.qlik.com/en-US/nprinting/April2018/APIs/NP+API/index.html#TaskExecution for more info.

0 Likes
Partner
Partner

It seems you are not taking into account the Warned/warning status, or am I missing something?

0 Likes
Partner
Partner

Just add it to the last page, I would recommend both Warning and CompletedWithWarning.

0 Likes
Partner
Partner

Don't need to add it I have my own script . And using a connection to postgres mostly because you can't get trigger info from API. My script triggers are configurable with NPrinting triggers(disabled triggers ofcourse).

0 Likes
Employee
Employee

‌hey guys - thanks for the suggestions about adding a set more task execution statuses to the check. Great input .  I’ve posted a couple other community docs that use this technique around distributing reports and updating users  . 

The overall idea is to operate nprinting from one scheduler : either publisher or Sense scheduler which is a strategic desire for most enterprise customers as we can tap into a lot of scheduler capabilities like admin error notification and task chaining upon success/failure that are already built into those schedulers .  It brings those capabilities to NPrinting while making things potentiallly easier to manage and highly flexible by using standard QlikTech developer techniques ... a coding language that qlik , community and partners all provide services and training for . 

KEep then coming !

0 Likes
Partner
Partner

The admin error notification in Sense does not send an email notification and only shows in the QMC. Please add email notifications.

0 Likes
Employee
Employee

I've got 3 ways to go with the admin notification:

1.  Use a Qlik Sense based utility

There are 3rd party utilities on branch / github . The reason i suggest this first is that may customers will have an existing utility to monitor there QVD builds and Dashboard reloads for failures. The same utility can be used for nprinting failure notifications if you are triggering the nprinting tasks using the qlik load script as in these examples. Let me know if you want more information on any of these.

Qlik Branch

2.  Use NPrinting for admin notification

Should the NPrinting publish task fail, we can just add a 2nd task execution to the script to run a generic publish task that just sends an email to an administrator. 

3. Use the Qlik Notification Web Connector

I threw this in in case NPrinting was completely down. #2 wouldn't work in that case.  The Qlik Sense notification connector can call an SMTP server and send an email directly from the load script.

https://help.qlik.com/en-US/connectors/Subsystems/Web_Connectors_help/Content/Data-Source-Connectors...

0 Likes
Partner
Partner

I have my own Task monitor deployed at our customers for this(using notification connector). But it seemed like you were saying it was a native function of the QMC to notify an admin something went wrong. Which it is not. In QV it is possible to get alerts.

0 Likes
Partner
Partner

Just want to add a warning here.

If you are dependent on conditions and similar in NPrinting, remember that it takes some time for an app to get published.

We added an extra "delay reloads app" in QS chain so that it has enough time to publish the app before NPrinting picks up conditions and other things, which it depends on. A 430 mb app takes 39 seconds in our DEV environment to get published.

Name a sample document to e.g. "Delay reloads in minutes by_2". Change title after _ to set timeout so that you don't have to change the code for each setup.

Code:

let vTimeoutMinutes = subfield(DocumentTitle(), 'minutes by_', '-1') ; // timeout in Minutes
let vTimeoutSeconds = vTimeoutMinutes * 60 * 1000 ; // convert to seconds

sleep vTimeoutSeconds;

0 Likes
Version history
Revision #:
1 of 1
Last update:
‎2018-04-10 09:27 AM
Updated by: