Reporting and Maintaining Progress in Your Nom Nom App

Reporting and Maintaining Progress in Your Nom Nom App

This article explains the best practices for reporting Task progress in your Nom Nom App code and for updating a parameter value in a Task from your Nom Nom App code so that you can maintain progress across multiple Task executions.  Specifically it focuses on using the engine.update_progress and the engine.update_parameter functions.  It is assumed that the reader is already familiar with the information in the Creating Your First Nom Nom App article.

Reporting Progress During Task Execution

The following examples demonstrate the use of the engine.update_progress function to inform users how far your code has progressed during various points of a Task execution.  The progress variable is passed into the function with a value set between 0 and 100.  Each time the function is called, this portion of the Nominode Task user interface is updated to display the value passed to the function as a percentage and to update the fill amount in a progress bar:



The function could just be called between sections of your App code:

download_data_function()
engine.update_progress(progress=25)
process_data_function()
engine.update_progress(progress=50)
upload_processed_data_function()
engine.update_progress(progress=75)
cleanup_function()
engine.update_progress(progress=100)

But a more useful application is to find the portions of your App code where it is looping several times and call the function at certain intervals within those loops passing in progress values based on the size of the loop:

i = 0
total = 5000
while i < total:
     i += 1
     five_percent = round(total * .05) or 1
     if i % five_percent == 0:
          p = "%.2f" % ((i / total) * 100)
          engine.update_progress(progress=p)
          logger.info(f"Processed {p}% of the data.")

Retaining Progress Between Task Executions

Many Nom Nom Apps are designed to be run on a regular schedule using a Task triggered by a Sequence rather than just being run a single time.  And often they are running to download or process "new" data.  Meaning they want to begin their activity at the point in the data where the previous Task execution ended.  The following example demonstrates the use of the engine.update_parameter function to write the datetime stamp of when the Task began its execution to a parameter called last_run in the Task:

start_time = datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S%z")
download_new_data_function(start_point=params["last_run"])
engine.update_parameter("last_run", start_time)

The value stored and updated in the last_run parameter is also passed as the starting point value into the function that downloads data, which ensures that, each time the Task runs, it is downloading data created between the previous time it ran and the current time.  This example relies on the data to download being sorted by a created or updated date and the API used to access it including an option to allow subset extraction based on a date.  But the function is equally applicable to any type of persistent pointer value that can be used to traverse through a set of data via multiple Task executions.