django-database-task 0.3.1__tar.gz → 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. django_database_task-0.5.0/CHANGELOG.md +145 -0
  2. {django_database_task-0.3.1 → django_database_task-0.5.0}/MANIFEST.in +1 -0
  3. django_database_task-0.5.0/PKG-INFO +2061 -0
  4. django_database_task-0.5.0/README.md +2019 -0
  5. {django_database_task-0.3.1 → django_database_task-0.5.0}/django_database_task/__init__.py +3 -1
  6. {django_database_task-0.3.1 → django_database_task-0.5.0}/django_database_task/admin.py +40 -1
  7. django_database_task-0.5.0/django_database_task/auth.py +314 -0
  8. {django_database_task-0.3.1 → django_database_task-0.5.0}/django_database_task/backends.py +210 -7
  9. django_database_task-0.5.0/django_database_task/brokers/__init__.py +10 -0
  10. django_database_task-0.5.0/django_database_task/brokers/base.py +187 -0
  11. {django_database_task-0.3.1 → django_database_task-0.5.0}/django_database_task/cloudtasks/__init__.py +9 -5
  12. {django_database_task-0.3.1 → django_database_task-0.5.0}/django_database_task/cloudtasks/auth.py +6 -6
  13. django_database_task-0.5.0/django_database_task/cloudtasks/backend.py +57 -0
  14. django_database_task-0.5.0/django_database_task/cloudtasks/broker.py +180 -0
  15. django_database_task-0.5.0/django_database_task/exceptions.py +20 -0
  16. {django_database_task-0.3.1 → django_database_task-0.5.0}/django_database_task/executor.py +212 -0
  17. django_database_task-0.5.0/django_database_task/locale/ja/LC_MESSAGES/django.mo +0 -0
  18. {django_database_task-0.3.1 → django_database_task-0.5.0}/django_database_task/locale/ja/LC_MESSAGES/django.po +7 -3
  19. django_database_task-0.5.0/django_database_task/management/commands/requeue_stale_database_tasks.py +180 -0
  20. django_database_task-0.5.0/django_database_task/management/commands/run_database_tasks.py +545 -0
  21. django_database_task-0.5.0/django_database_task/postgres/__init__.py +41 -0
  22. django_database_task-0.5.0/django_database_task/postgres/backend.py +41 -0
  23. django_database_task-0.5.0/django_database_task/postgres/broker.py +329 -0
  24. django_database_task-0.5.0/django_database_task/sqs/__init__.py +58 -0
  25. django_database_task-0.5.0/django_database_task/sqs/backend.py +40 -0
  26. django_database_task-0.5.0/django_database_task/sqs/broker.py +253 -0
  27. django_database_task-0.5.0/django_database_task/sqs/detection.py +35 -0
  28. {django_database_task-0.3.1 → django_database_task-0.5.0}/django_database_task/views.py +50 -21
  29. django_database_task-0.5.0/django_database_task.egg-info/PKG-INFO +2061 -0
  30. {django_database_task-0.3.1 → django_database_task-0.5.0}/django_database_task.egg-info/SOURCES.txt +18 -0
  31. {django_database_task-0.3.1 → django_database_task-0.5.0}/django_database_task.egg-info/requires.txt +7 -0
  32. {django_database_task-0.3.1 → django_database_task-0.5.0}/pyproject.toml +19 -2
  33. {django_database_task-0.3.1 → django_database_task-0.5.0}/tests/test_admin.py +62 -0
  34. django_database_task-0.5.0/tests/test_auth.py +380 -0
  35. django_database_task-0.5.0/tests/test_brokers.py +288 -0
  36. django_database_task-0.5.0/tests/test_commands.py +957 -0
  37. django_database_task-0.5.0/tests/test_logging.py +177 -0
  38. django_database_task-0.5.0/tests/test_requeue.py +481 -0
  39. {django_database_task-0.3.1 → django_database_task-0.5.0}/tests/test_views.py +146 -7
  40. django_database_task-0.3.1/PKG-INFO +0 -1052
  41. django_database_task-0.3.1/README.md +0 -1015
  42. django_database_task-0.3.1/django_database_task/cloudtasks/backend.py +0 -239
  43. django_database_task-0.3.1/django_database_task/locale/ja/LC_MESSAGES/django.mo +0 -0
  44. django_database_task-0.3.1/django_database_task/management/commands/run_database_tasks.py +0 -197
  45. django_database_task-0.3.1/django_database_task.egg-info/PKG-INFO +0 -1052
  46. django_database_task-0.3.1/tests/test_commands.py +0 -417
  47. {django_database_task-0.3.1 → django_database_task-0.5.0}/LICENSE +0 -0
  48. {django_database_task-0.3.1 → django_database_task-0.5.0}/django_database_task/apps.py +0 -0
  49. {django_database_task-0.3.1 → django_database_task-0.5.0}/django_database_task/cloudtasks/detection.py +0 -0
  50. {django_database_task-0.3.1 → django_database_task-0.5.0}/django_database_task/management/__init__.py +0 -0
  51. {django_database_task-0.3.1 → django_database_task-0.5.0}/django_database_task/management/commands/__init__.py +0 -0
  52. {django_database_task-0.3.1 → django_database_task-0.5.0}/django_database_task/management/commands/purge_completed_database_tasks.py +0 -0
  53. {django_database_task-0.3.1 → django_database_task-0.5.0}/django_database_task/migrations/0001_initial.py +0 -0
  54. {django_database_task-0.3.1 → django_database_task-0.5.0}/django_database_task/migrations/__init__.py +0 -0
  55. {django_database_task-0.3.1 → django_database_task-0.5.0}/django_database_task/models.py +0 -0
  56. {django_database_task-0.3.1 → django_database_task-0.5.0}/django_database_task/shutdown.py +0 -0
  57. {django_database_task-0.3.1 → django_database_task-0.5.0}/django_database_task/urls.py +0 -0
  58. {django_database_task-0.3.1 → django_database_task-0.5.0}/django_database_task.egg-info/dependency_links.txt +0 -0
  59. {django_database_task-0.3.1 → django_database_task-0.5.0}/django_database_task.egg-info/top_level.txt +0 -0
  60. {django_database_task-0.3.1 → django_database_task-0.5.0}/setup.cfg +0 -0
  61. {django_database_task-0.3.1 → django_database_task-0.5.0}/tests/test_backend.py +0 -0
  62. {django_database_task-0.3.1 → django_database_task-0.5.0}/tests/test_executor.py +0 -0
  63. {django_database_task-0.3.1 → django_database_task-0.5.0}/tests/test_models.py +0 -0
  64. {django_database_task-0.3.1 → django_database_task-0.5.0}/tests/test_shutdown.py +0 -0
@@ -0,0 +1,145 @@
1
+ # Changelog
2
+
3
+ ## 0.5.0
4
+
5
+ ### Added
6
+
7
+ - **Recovery of tasks left in `RUNNING`**
8
+ (`manage.py requeue_stale_database_tasks --older-than 15m`). A worker killed
9
+ outright — SIGKILL, the OOM killer, a node failure — never writes a result,
10
+ so the task it held stays `RUNNING` and no other worker picks it up. The new
11
+ command finds those tasks and puts them back in `READY`. Previously the only
12
+ way out was a hand-written query.
13
+ - `--older-than` is required and takes a unit (`90s`, `15m`, `2h`, `1d`). It
14
+ has to be longer than the longest task takes to run: nothing distinguishes a
15
+ dead worker from a slow task, so a threshold below that requeues tasks that
16
+ are still running.
17
+ - `--max-attempts` (default 3) marks a task `FAILED` instead of requeueing it
18
+ once it has been handed to that many workers, so a task that kills its own
19
+ worker cannot be requeued forever.
20
+ - `--mark-failed` records stale tasks as `FAILED` without requeueing them, for
21
+ tasks that are not safe to run twice, and `--notify-broker` re-notifies the
22
+ broker for workers that only receive from one. Also available as
23
+ `django_database_task.requeue_stale_tasks()` and as a "Requeue tasks stuck in
24
+ running" action in the Django admin.
25
+ - **PostgreSQL LISTEN/NOTIFY broker**
26
+ (`django_database_task.postgres.PostgresNotifyDatabaseBackend`). Notifies a
27
+ channel of the database the tasks are already stored in, so a waiting worker
28
+ starts the task in milliseconds instead of on the next poll. It needs no
29
+ queue, no credentials and no extra service — only the PostgreSQL connection
30
+ the project already has.
31
+ - The notification is sent with `pg_notify()` on the connection that inserted
32
+ the task and inside the same transaction, so PostgreSQL delivers it on
33
+ commit. A worker is never told about a task it cannot yet see, or one whose
34
+ transaction was rolled back.
35
+ - A `postgres` extra, for a project that has not installed a PostgreSQL driver
36
+ yet. psycopg 3 and psycopg2 both work.
37
+ - **Exit codes for job schedulers**: `run_database_tasks --empty-exit-code` and
38
+ `--failed-exit-code`. An on-premise scheduler (JP1, Hinemos, Rundeck, cron, a
39
+ systemd timer) decides what happened from the exit code, and the command
40
+ previously exited 0 whether it drained the queue, found nothing, or ran a
41
+ task that failed. Both options default to 0, so nothing changes for an
42
+ existing `cron` line or Kubernetes `Job` until they are set. A failed task
43
+ outranks an idle run; a broker that could not be reached is neither.
44
+ - **Structured log fields.** The library's log records now carry their context
45
+ as attributes — `task_id`, `task_path`, `queue_name`, `priority`,
46
+ `backend_alias`, `worker_id`, plus `status`, `duration_ms` and `error_class`
47
+ where they apply — instead of only interpolating it into the message. A JSON
48
+ formatter now emits fields an operator can filter on. `Task started`,
49
+ `Worker started` and `Worker finished` records are new; the last carries
50
+ `tasks_processed`, `tasks_failed` and `exit_code`.
51
+ - Documentation for running the worker from a job scheduler: the exit code
52
+ table, `flock` for keeping a slow run from being overlapped by the next one,
53
+ systemd unit samples for both the timer-driven and the long-running shape,
54
+ and a `LOGGING` configuration that produces JSON.
55
+
56
+ ### Changed
57
+
58
+ - A broker's `enqueue()` method is now called `notify()`. The old name read as
59
+ if it enqueued the task, which is the backend's job: a broker is only told
60
+ about a task the database already holds, and carries nothing but its id. The
61
+ new name matches what the method does, what `notify_broker()` is called and
62
+ what every broker docstring already said.
63
+ - The log record for a broker failure now reads `Broker X failed to notify
64
+ about task Y`, in place of `failed to enqueue task`.
65
+
66
+ ### Deprecated
67
+
68
+ - `TaskBroker.enqueue()`. A broker that overrides it is still called, with a
69
+ `DeprecationWarning`, and stops being called in 0.6. Rename it to `notify()`.
70
+ Bundled brokers and the `BROKER` option are unaffected; only a broker written
71
+ by hand against 0.4 needs the change.
72
+
73
+ ### Removed
74
+
75
+ - `get_auth_handler()` (singular), deprecated in 0.4 and removed here as
76
+ announced. A backend that overrides it is no longer called and its endpoints
77
+ fall back to whatever `get_auth_handlers()` returns — which, unless the
78
+ backend also overrides that or sets `AUTH_HANDLERS`, is nothing, leaving the
79
+ endpoints unauthenticated. Override `get_auth_handlers()` instead. The
80
+ `CLOUD_TASKS_*` options, `AUTH_HANDLERS` and the bundled backends are
81
+ unaffected.
82
+
83
+ ## 0.4.0
84
+
85
+ Brokers — the services that trigger execution of a saved task — are now
86
+ separate from the task backend, and Amazon SQS joins Cloud Tasks as one of
87
+ them.
88
+
89
+ **Existing projects need no changes.** The settings, the URLs, the management
90
+ commands and their defaults all behave as they did in 0.3.
91
+
92
+ ### Added
93
+
94
+ - **Amazon SQS broker** (`django_database_task.sqs.SQSDatabaseBackend`,
95
+ `pip install django-database-task[sqs]`). Sends a message naming the task,
96
+ and `run_database_tasks` receives it. A task deferred beyond the 15 minute
97
+ SQS delay limit stays in the database for the worker's database sweep.
98
+ - **`--source` for `run_database_tasks`**: `auto` (default), `db`, `broker` or
99
+ `both`. `auto` means `both` when the backend has a broker a worker can
100
+ receive from, and `db` otherwise, so the command is run the same way as
101
+ before either way. `--wait-time` and `--max-messages` go with it.
102
+ - **The broker abstraction** (`django_database_task.brokers`): `TaskBroker`,
103
+ `HTTPPushBroker` and `PullBroker`. A project attaches its own with the
104
+ `BROKER` option.
105
+ - **Several authentication handlers per backend**, through
106
+ `get_auth_handlers()`. A request is accepted as soon as one handler accepts
107
+ it, so the service that calls the endpoints and an external cron job can use
108
+ different credentials. Configure them with the `AUTH_HANDLERS` option, and
109
+ limit one to some endpoints with `ENDPOINTS`.
110
+ - **Bundled authentication handlers** in `django_database_task.auth`:
111
+ `SharedSecretAuth`, `HMACAuth` and `StaffOnlyAuth`, with `build_signature()`
112
+ for callers that have to sign a request for `HMACAuth`.
113
+ - **AWS environment detection** in `django_database_task.sqs`:
114
+ `detect_aws_region()`, `is_lambda()` and `is_ecs()`, alongside the existing
115
+ Cloud Tasks ones.
116
+ - The brokers themselves are importable, for a project that wants one on a
117
+ backend of its own: `django_database_task.sqs.SQSBroker` and
118
+ `django_database_task.cloudtasks.CloudTasksBroker`.
119
+
120
+ ### Fixed
121
+
122
+ - Enabling Cloud Tasks OIDC no longer locks every other caller out of the task
123
+ endpoints. Since 0.3.1 the OIDC handler was applied to all of them, so an
124
+ external cron job calling `/tasks/run/` or `/tasks/purge/` was rejected.
125
+ - The Cloud Tasks tests were skipped on every run, in CI included, because the
126
+ `cloudtasks` extra was never installed. Four of them had gone stale
127
+ unnoticed.
128
+
129
+ ### Deprecated
130
+
131
+ - `get_auth_handler()` (singular). It still works, with a
132
+ `DeprecationWarning`, and is removed in 0.5. Override `get_auth_handlers()`
133
+ instead.
134
+
135
+ ### Documentation
136
+
137
+ - A *Task Brokers* section in the README, and an Amazon SQS one with a
138
+ sequence diagram beside the ones the database backend and Cloud Tasks
139
+ already had.
140
+ - An SQS walkthrough in `examples/`, run against a local mock: set
141
+ `DEMO_BROKER=sqs` to point the demo project at it.
142
+ - `CONTRIBUTING.md`, covering the development setup, the tests, and how to add
143
+ a broker.
144
+ - This file. Releases before 0.4.0 are in the git history and the GitHub
145
+ releases.
@@ -1,3 +1,4 @@
1
1
  include LICENSE
2
2
  include README.md
3
+ include CHANGELOG.md
3
4
  recursive-include django_database_task/locale *.po *.mo