Skip to content

Commit 6c39872

Browse files
author
James (ODSC)
authored
Merge pull request #15 from OpenDataServices/2024-10-09
2024 10 09
2 parents 7034f2c + f3d2d5b commit 6c39872

File tree

6 files changed

+67
-10
lines changed

6 files changed

+67
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
## Changed
11+
12+
- In `TaskWithState.process_get_state()` any changes to `process_data` are now ignored. https://github.com/OpenDataServices/lib-cove-web-2/issues/14
13+
1014
## [0.3.0] - 2023-09-14
1115

1216
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.

docs/hosting/index.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Hosting
2+
=======
3+
4+
5+
6+
.. toctree::
7+
:maxdepth: 2
8+
9+
requirements.rst
10+
with_dokku.rst

docs/hosting/requirements.rst

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
Hosting Requirements
22
====================
33

4-
Python server for the Django app
5-
----------------------------------
6-
7-
Normal options
8-
94
Database
105
----------
116

@@ -19,7 +14,36 @@ Normal options
1914
File Storage
2015
------------
2116

22-
TODO
17+
A file storage area is needed. This holds the files supplied by users, and the cached results of processing.
18+
19+
All code access in this library to the file storage area should be through Django `DefaultStorage` API.
20+
This means in theory, you are free to use:
21+
22+
* file storage by setting `MEDIA_ROOT` and `MEDIA_URL`.
23+
* cloud bucket solutions (eg AWS S3, Azure Storage Container).
24+
* any other Django compatible Storage API.
25+
26+
Nothing in this library requires the contents of this storage to be served on the web.
27+
28+
However, code in apps that uses this library may have:
29+
30+
* direct access to the file system, in which case file storage by setting `MEDIA_ROOT` and `MEDIA_URL` is required.
31+
* direct users to URL's for download, in which case the contents of this storage must be served on the web.
32+
33+
All apps that use this library currently just use direct file storage by setting `MEDIA_ROOT` and `MEDIA_URL`,
34+
and that should be considered the only tested solution.
35+
36+
37+
Python web server for the Django app
38+
------------------------------------
39+
40+
Normal options
41+
42+
43+
A background worker
44+
-------------------
45+
46+
Run using Celery's normal run options.
2347

2448
Cron tasks
2549
----------

docs/hosting/with_dokku.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Hosting with Dokku
2+
==================
3+
4+
For examples of this, see:
5+
6+
* https://github.com/openownership/cove-bods
7+
* https://github.com/Open-Telecoms-Data/cove-ofds
8+
* https://github.com/GFDRR/rdls-cove

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ The application consists of:
2626
django-settings.rst
2727
python-api/index.rst
2828
migration-from-lib-cove-web.rst
29-
hosting/requirements.rst
29+
hosting/index.rst
3030
used-by.rst
3131

libcoveweb2/process/common_tasks/task_with_state.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@
1010
class TaskWithState(ProcessDataTask):
1111
"""An abstract task that helps you save state from
1212
the processing step and add it to the context.
13+
14+
It will cache one JSON blob for you, and add
15+
it to the view context when a user is looking at the results.
16+
(So make sure you choose keys in the JSON blob carefully
17+
so as not to clash with other view context variables!)
18+
1319
Extend and provide your own state_filename and process_get_state.
1420
"""
1521

1622
#: Set state_filename to a unique name for each task.
1723
#:
18-
#: If you change this name the task will be rerun, so this is is a good way to
24+
#: If you change this name the task will be rerun, so this is a good way to
1925
#: make sure all underlying data changes if a new version of this bit of cove
2026
#: is released.
2127
state_filename: str = "task_with_state.json"
@@ -28,14 +34,19 @@ def process_get_state(self, process_data: dict):
2834
2935
Should return a tuple.
3036
The first item is the results to save, as a dictionary.
31-
The second item is process_data, as a dictionary."""
37+
The second item is process_data, as a dictionary.
38+
39+
Do NOT change process_data in this function!
40+
The fact it's returned is a mistake:
41+
https://github.com/OpenDataServices/lib-cove-web-2/issues/14
42+
"""
3243
return {}, process_data
3344

3445
def process(self, process_data: dict) -> dict:
3546
if self.does_state_exist():
3647
return process_data
3748

38-
state, process_data = self.process_get_state(process_data)
49+
state, process_data_throw_away = self.process_get_state(process_data)
3950

4051
default_storage.save(
4152
os.path.join(self.supplied_data.storage_dir(), self.state_filename),

0 commit comments

Comments
 (0)