Skip to content

Commit

Permalink
TaskWithState.process_get_state(), any changes to process_data now ig…
Browse files Browse the repository at this point in the history
…nored

#14

And docs: #13
  • Loading branch information
jarofgreen committed Oct 9, 2024
1 parent 7034f2c commit b206b23
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## Changed

- In `TaskWithState.process_get_state()` any changes to `process_data` are now ignored. https://github.com/OpenDataServices/lib-cove-web-2/issues/14

## [0.3.0] - 2023-09-14

When upgrading to this version, `ALLOWED_UNKNOWN_CONTENT_TYPES` must be set in the Django settings file, ideally from the settings file included with this library.
Expand Down
17 changes: 14 additions & 3 deletions libcoveweb2/process/common_tasks/task_with_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@
class TaskWithState(ProcessDataTask):
"""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.
"""

#: Set state_filename to a unique name for each task.
#:
#: If you change this name the task will be rerun, so this is is a good way to
#: 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.
state_filename: str = "task_with_state.json"
Expand All @@ -28,14 +34,19 @@ def process_get_state(self, process_data: dict):
Should return a tuple.
The first item is the results to save, as a dictionary.
The second item is process_data, 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
"""
return {}, process_data

def process(self, process_data: dict) -> dict:
if self.does_state_exist():
return process_data

state, process_data = self.process_get_state(process_data)
state, process_data_throw_away = self.process_get_state(process_data)

default_storage.save(
os.path.join(self.supplied_data.storage_dir(), self.state_filename),
Expand Down

0 comments on commit b206b23

Please sign in to comment.