Common Process Task: Task With State

class libfjordweb.process.common_tasks.task_with_state.TaskWithState(supplied_data: SuppliedData, supplied_data_files: List[SuppliedDataFile])

An abstract task that helps you save state from the processing step and add it to the context.

It will cache one JSON blob for you, and add it to the view context when a user is looking at the results. (So make sure you choose keys in the JSON blob carefully so as not to clash with other view context variables!)

Extend and provide your own state_filename and process_get_state.

process_get_state(process_data: dict)

Called to process data.

Is only called if there is work to do, so does not need to worry about checking that.

Should return a tuple. The first item is the results to save, as a dictionary. The second item is process_data, as a dictionary.

Do NOT change process_data in this function! The fact it’s returned is a mistake: https://github.com/OpenDataServices/lib-cove-web-2/issues/14

state_filename: str = 'task_with_state.json'

Set state_filename to a unique name for each task.

If you change this name the task will be rerun, so this is a good way to make sure all underlying data changes if a new version of this bit of cove is released.