plain.jobs 0.43.2__py3-none-any.whl
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.
- plain/jobs/CHANGELOG.md +461 -0
- plain/jobs/README.md +300 -0
- plain/jobs/__init__.py +6 -0
- plain/jobs/admin.py +249 -0
- plain/jobs/chores.py +19 -0
- plain/jobs/cli.py +204 -0
- plain/jobs/config.py +19 -0
- plain/jobs/default_settings.py +6 -0
- plain/jobs/exceptions.py +34 -0
- plain/jobs/jobs.py +368 -0
- plain/jobs/locks.py +42 -0
- plain/jobs/middleware.py +42 -0
- plain/jobs/migrations/0001_initial.py +246 -0
- plain/jobs/migrations/0002_job_span_id_job_trace_id_jobrequest_span_id_and_more.py +61 -0
- plain/jobs/migrations/0003_rename_job_jobprocess_and_more.py +80 -0
- plain/jobs/migrations/0004_rename_tables_to_plainjobs.py +33 -0
- plain/jobs/migrations/0005_rename_constraints_and_indexes.py +174 -0
- plain/jobs/migrations/0006_alter_jobprocess_table_alter_jobrequest_table_and_more.py +24 -0
- plain/jobs/migrations/0007_remove_jobrequest_plainjobs_jobrequest_unique_job_class_key_and_more.py +144 -0
- plain/jobs/migrations/__init__.py +0 -0
- plain/jobs/models.py +567 -0
- plain/jobs/parameters.py +193 -0
- plain/jobs/registry.py +60 -0
- plain/jobs/scheduling.py +253 -0
- plain/jobs/templates/admin/plainqueue/jobresult_detail.html +8 -0
- plain/jobs/workers.py +355 -0
- plain_jobs-0.43.2.dist-info/METADATA +312 -0
- plain_jobs-0.43.2.dist-info/RECORD +30 -0
- plain_jobs-0.43.2.dist-info/WHEEL +4 -0
- plain_jobs-0.43.2.dist-info/licenses/LICENSE +28 -0
plain/jobs/middleware.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
from collections.abc import Callable
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
from plain.logs import app_logger
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from .models import JobProcess, JobResult
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class JobMiddleware(ABC):
|
|
14
|
+
"""
|
|
15
|
+
Abstract base class for job middleware.
|
|
16
|
+
|
|
17
|
+
Subclasses must implement process_job() to handle the job execution cycle.
|
|
18
|
+
|
|
19
|
+
Example:
|
|
20
|
+
class MyJobMiddleware(JobMiddleware):
|
|
21
|
+
def process_job(self, job: JobProcess) -> JobResult:
|
|
22
|
+
# Pre-processing
|
|
23
|
+
result = self.run_job(job)
|
|
24
|
+
# Post-processing
|
|
25
|
+
return result
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
def __init__(self, run_job: Callable[[JobProcess], JobResult]):
|
|
29
|
+
self.run_job = run_job
|
|
30
|
+
|
|
31
|
+
@abstractmethod
|
|
32
|
+
def process_job(self, job: JobProcess) -> JobResult:
|
|
33
|
+
"""Process the job and return a result. Must be implemented by subclasses."""
|
|
34
|
+
...
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class AppLoggerMiddleware(JobMiddleware):
|
|
38
|
+
def process_job(self, job: JobProcess) -> JobResult:
|
|
39
|
+
with app_logger.include_context(
|
|
40
|
+
job_request_uuid=str(job.job_request_uuid), job_process_uuid=str(job.uuid)
|
|
41
|
+
):
|
|
42
|
+
return self.run_job(job)
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# Generated by Plain 0.52.2 on 2025-07-08 01:17
|
|
2
|
+
|
|
3
|
+
import uuid
|
|
4
|
+
|
|
5
|
+
from plain import models
|
|
6
|
+
from plain.models import migrations
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Migration(migrations.Migration):
|
|
10
|
+
initial = True
|
|
11
|
+
|
|
12
|
+
dependencies = []
|
|
13
|
+
|
|
14
|
+
operations = [
|
|
15
|
+
migrations.CreateModel(
|
|
16
|
+
name="Job",
|
|
17
|
+
fields=[
|
|
18
|
+
("id", models.PrimaryKeyField()),
|
|
19
|
+
("uuid", models.UUIDField(default=uuid.uuid4)),
|
|
20
|
+
("created_at", models.DateTimeField(auto_now_add=True)),
|
|
21
|
+
("started_at", models.DateTimeField(allow_null=True, required=False)),
|
|
22
|
+
("job_request_uuid", models.UUIDField()),
|
|
23
|
+
("job_class", models.CharField(max_length=255)),
|
|
24
|
+
("parameters", models.JSONField(allow_null=True, required=False)),
|
|
25
|
+
("priority", models.IntegerField(default=0)),
|
|
26
|
+
("source", models.TextField(required=False)),
|
|
27
|
+
("queue", models.CharField(default="default", max_length=255)),
|
|
28
|
+
("retries", models.IntegerField(default=0)),
|
|
29
|
+
("retry_attempt", models.IntegerField(default=0)),
|
|
30
|
+
("unique_key", models.CharField(max_length=255, required=False)),
|
|
31
|
+
],
|
|
32
|
+
options={
|
|
33
|
+
"ordering": ["-created_at"],
|
|
34
|
+
},
|
|
35
|
+
),
|
|
36
|
+
migrations.CreateModel(
|
|
37
|
+
name="JobRequest",
|
|
38
|
+
fields=[
|
|
39
|
+
("id", models.PrimaryKeyField()),
|
|
40
|
+
("created_at", models.DateTimeField(auto_now_add=True)),
|
|
41
|
+
("uuid", models.UUIDField(default=uuid.uuid4)),
|
|
42
|
+
("job_class", models.CharField(max_length=255)),
|
|
43
|
+
("parameters", models.JSONField(allow_null=True, required=False)),
|
|
44
|
+
("priority", models.IntegerField(default=0)),
|
|
45
|
+
("source", models.TextField(required=False)),
|
|
46
|
+
("queue", models.CharField(default="default", max_length=255)),
|
|
47
|
+
("retries", models.IntegerField(default=0)),
|
|
48
|
+
("retry_attempt", models.IntegerField(default=0)),
|
|
49
|
+
("unique_key", models.CharField(max_length=255, required=False)),
|
|
50
|
+
("start_at", models.DateTimeField(allow_null=True, required=False)),
|
|
51
|
+
],
|
|
52
|
+
options={
|
|
53
|
+
"ordering": ["priority", "-created_at"],
|
|
54
|
+
},
|
|
55
|
+
),
|
|
56
|
+
migrations.CreateModel(
|
|
57
|
+
name="JobResult",
|
|
58
|
+
fields=[
|
|
59
|
+
("id", models.PrimaryKeyField()),
|
|
60
|
+
("uuid", models.UUIDField(default=uuid.uuid4)),
|
|
61
|
+
("created_at", models.DateTimeField(auto_now_add=True)),
|
|
62
|
+
("job_uuid", models.UUIDField()),
|
|
63
|
+
("started_at", models.DateTimeField(allow_null=True, required=False)),
|
|
64
|
+
("ended_at", models.DateTimeField(allow_null=True, required=False)),
|
|
65
|
+
("error", models.TextField(required=False)),
|
|
66
|
+
(
|
|
67
|
+
"status",
|
|
68
|
+
models.CharField(
|
|
69
|
+
choices=[
|
|
70
|
+
("SUCCESSFUL", "Successful"),
|
|
71
|
+
("ERRORED", "Errored"),
|
|
72
|
+
("CANCELLED", "Cancelled"),
|
|
73
|
+
("LOST", "Lost"),
|
|
74
|
+
],
|
|
75
|
+
max_length=20,
|
|
76
|
+
),
|
|
77
|
+
),
|
|
78
|
+
("job_request_uuid", models.UUIDField()),
|
|
79
|
+
("job_class", models.CharField(max_length=255)),
|
|
80
|
+
("parameters", models.JSONField(allow_null=True, required=False)),
|
|
81
|
+
("priority", models.IntegerField(default=0)),
|
|
82
|
+
("source", models.TextField(required=False)),
|
|
83
|
+
("queue", models.CharField(default="default", max_length=255)),
|
|
84
|
+
("retries", models.IntegerField(default=0)),
|
|
85
|
+
("retry_attempt", models.IntegerField(default=0)),
|
|
86
|
+
("unique_key", models.CharField(max_length=255, required=False)),
|
|
87
|
+
(
|
|
88
|
+
"retry_job_request_uuid",
|
|
89
|
+
models.UUIDField(allow_null=True, required=False),
|
|
90
|
+
),
|
|
91
|
+
],
|
|
92
|
+
options={
|
|
93
|
+
"ordering": ["-created_at"],
|
|
94
|
+
},
|
|
95
|
+
),
|
|
96
|
+
migrations.AddIndex(
|
|
97
|
+
model_name="job",
|
|
98
|
+
index=models.Index(
|
|
99
|
+
fields=["created_at"], name="plainworker_created_a02317_idx"
|
|
100
|
+
),
|
|
101
|
+
),
|
|
102
|
+
migrations.AddIndex(
|
|
103
|
+
model_name="job",
|
|
104
|
+
index=models.Index(fields=["queue"], name="plainworker_queue_077806_idx"),
|
|
105
|
+
),
|
|
106
|
+
migrations.AddIndex(
|
|
107
|
+
model_name="job",
|
|
108
|
+
index=models.Index(
|
|
109
|
+
fields=["unique_key"], name="plainworker_unique__04d87b_idx"
|
|
110
|
+
),
|
|
111
|
+
),
|
|
112
|
+
migrations.AddIndex(
|
|
113
|
+
model_name="job",
|
|
114
|
+
index=models.Index(
|
|
115
|
+
fields=["started_at"], name="plainworker_started_143df5_idx"
|
|
116
|
+
),
|
|
117
|
+
),
|
|
118
|
+
migrations.AddIndex(
|
|
119
|
+
model_name="job",
|
|
120
|
+
index=models.Index(
|
|
121
|
+
fields=["job_class"], name="plainworker_job_cla_884b46_idx"
|
|
122
|
+
),
|
|
123
|
+
),
|
|
124
|
+
migrations.AddIndex(
|
|
125
|
+
model_name="job",
|
|
126
|
+
index=models.Index(
|
|
127
|
+
fields=["job_request_uuid"], name="plainworker_job_req_db2681_idx"
|
|
128
|
+
),
|
|
129
|
+
),
|
|
130
|
+
migrations.AddIndex(
|
|
131
|
+
model_name="job",
|
|
132
|
+
index=models.Index(
|
|
133
|
+
fields=["job_class", "unique_key"], name="job_class_unique_key"
|
|
134
|
+
),
|
|
135
|
+
),
|
|
136
|
+
migrations.AddConstraint(
|
|
137
|
+
model_name="job",
|
|
138
|
+
constraint=models.UniqueConstraint(
|
|
139
|
+
fields=("uuid",), name="plainworker_job_unique_uuid"
|
|
140
|
+
),
|
|
141
|
+
),
|
|
142
|
+
migrations.AddIndex(
|
|
143
|
+
model_name="jobrequest",
|
|
144
|
+
index=models.Index(
|
|
145
|
+
fields=["priority"], name="plainworker_priorit_785e73_idx"
|
|
146
|
+
),
|
|
147
|
+
),
|
|
148
|
+
migrations.AddIndex(
|
|
149
|
+
model_name="jobrequest",
|
|
150
|
+
index=models.Index(
|
|
151
|
+
fields=["created_at"], name="plainworker_created_c81fe5_idx"
|
|
152
|
+
),
|
|
153
|
+
),
|
|
154
|
+
migrations.AddIndex(
|
|
155
|
+
model_name="jobrequest",
|
|
156
|
+
index=models.Index(fields=["queue"], name="plainworker_queue_2614aa_idx"),
|
|
157
|
+
),
|
|
158
|
+
migrations.AddIndex(
|
|
159
|
+
model_name="jobrequest",
|
|
160
|
+
index=models.Index(
|
|
161
|
+
fields=["start_at"], name="plainworker_start_a_4d6020_idx"
|
|
162
|
+
),
|
|
163
|
+
),
|
|
164
|
+
migrations.AddIndex(
|
|
165
|
+
model_name="jobrequest",
|
|
166
|
+
index=models.Index(
|
|
167
|
+
fields=["unique_key"], name="plainworker_unique__21a534_idx"
|
|
168
|
+
),
|
|
169
|
+
),
|
|
170
|
+
migrations.AddIndex(
|
|
171
|
+
model_name="jobrequest",
|
|
172
|
+
index=models.Index(
|
|
173
|
+
fields=["job_class"], name="plainworker_job_cla_3e7dea_idx"
|
|
174
|
+
),
|
|
175
|
+
),
|
|
176
|
+
migrations.AddIndex(
|
|
177
|
+
model_name="jobrequest",
|
|
178
|
+
index=models.Index(
|
|
179
|
+
fields=["job_class", "unique_key"], name="job_request_class_unique_key"
|
|
180
|
+
),
|
|
181
|
+
),
|
|
182
|
+
migrations.AddConstraint(
|
|
183
|
+
model_name="jobrequest",
|
|
184
|
+
constraint=models.UniqueConstraint(
|
|
185
|
+
condition=models.Q(("retry_attempt", 0), ("unique_key__gt", "")),
|
|
186
|
+
fields=("job_class", "unique_key"),
|
|
187
|
+
name="plainworker_jobrequest_unique_job_class_key",
|
|
188
|
+
),
|
|
189
|
+
),
|
|
190
|
+
migrations.AddConstraint(
|
|
191
|
+
model_name="jobrequest",
|
|
192
|
+
constraint=models.UniqueConstraint(
|
|
193
|
+
fields=("uuid",), name="plainworker_jobrequest_unique_uuid"
|
|
194
|
+
),
|
|
195
|
+
),
|
|
196
|
+
migrations.AddIndex(
|
|
197
|
+
model_name="jobresult",
|
|
198
|
+
index=models.Index(
|
|
199
|
+
fields=["created_at"], name="plainworker_created_6894c5_idx"
|
|
200
|
+
),
|
|
201
|
+
),
|
|
202
|
+
migrations.AddIndex(
|
|
203
|
+
model_name="jobresult",
|
|
204
|
+
index=models.Index(
|
|
205
|
+
fields=["job_uuid"], name="plainworker_job_uui_8307d1_idx"
|
|
206
|
+
),
|
|
207
|
+
),
|
|
208
|
+
migrations.AddIndex(
|
|
209
|
+
model_name="jobresult",
|
|
210
|
+
index=models.Index(
|
|
211
|
+
fields=["started_at"], name="plainworker_started_9bce76_idx"
|
|
212
|
+
),
|
|
213
|
+
),
|
|
214
|
+
migrations.AddIndex(
|
|
215
|
+
model_name="jobresult",
|
|
216
|
+
index=models.Index(
|
|
217
|
+
fields=["ended_at"], name="plainworker_ended_a_63caaf_idx"
|
|
218
|
+
),
|
|
219
|
+
),
|
|
220
|
+
migrations.AddIndex(
|
|
221
|
+
model_name="jobresult",
|
|
222
|
+
index=models.Index(fields=["status"], name="plainworker_status_a7ca35_idx"),
|
|
223
|
+
),
|
|
224
|
+
migrations.AddIndex(
|
|
225
|
+
model_name="jobresult",
|
|
226
|
+
index=models.Index(
|
|
227
|
+
fields=["job_request_uuid"], name="plainworker_job_req_1e1bf2_idx"
|
|
228
|
+
),
|
|
229
|
+
),
|
|
230
|
+
migrations.AddIndex(
|
|
231
|
+
model_name="jobresult",
|
|
232
|
+
index=models.Index(
|
|
233
|
+
fields=["job_class"], name="plainworker_job_cla_d138b5_idx"
|
|
234
|
+
),
|
|
235
|
+
),
|
|
236
|
+
migrations.AddIndex(
|
|
237
|
+
model_name="jobresult",
|
|
238
|
+
index=models.Index(fields=["queue"], name="plainworker_queue_23d8fe_idx"),
|
|
239
|
+
),
|
|
240
|
+
migrations.AddConstraint(
|
|
241
|
+
model_name="jobresult",
|
|
242
|
+
constraint=models.UniqueConstraint(
|
|
243
|
+
fields=("uuid",), name="plainworker_jobresult_unique_uuid"
|
|
244
|
+
),
|
|
245
|
+
),
|
|
246
|
+
]
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Generated by Plain 0.52.2 on 2025-07-17 19:33
|
|
2
|
+
|
|
3
|
+
from plain import models
|
|
4
|
+
from plain.models import migrations
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Migration(migrations.Migration):
|
|
8
|
+
dependencies = [
|
|
9
|
+
("plainjobs", "0001_initial"),
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
operations = [
|
|
13
|
+
migrations.AddField(
|
|
14
|
+
model_name="job",
|
|
15
|
+
name="span_id",
|
|
16
|
+
field=models.CharField(allow_null=True, max_length=18, required=False),
|
|
17
|
+
),
|
|
18
|
+
migrations.AddField(
|
|
19
|
+
model_name="job",
|
|
20
|
+
name="trace_id",
|
|
21
|
+
field=models.CharField(allow_null=True, max_length=34, required=False),
|
|
22
|
+
),
|
|
23
|
+
migrations.AddField(
|
|
24
|
+
model_name="jobrequest",
|
|
25
|
+
name="span_id",
|
|
26
|
+
field=models.CharField(allow_null=True, max_length=18, required=False),
|
|
27
|
+
),
|
|
28
|
+
migrations.AddField(
|
|
29
|
+
model_name="jobrequest",
|
|
30
|
+
name="trace_id",
|
|
31
|
+
field=models.CharField(allow_null=True, max_length=34, required=False),
|
|
32
|
+
),
|
|
33
|
+
migrations.AddField(
|
|
34
|
+
model_name="jobresult",
|
|
35
|
+
name="span_id",
|
|
36
|
+
field=models.CharField(allow_null=True, max_length=18, required=False),
|
|
37
|
+
),
|
|
38
|
+
migrations.AddField(
|
|
39
|
+
model_name="jobresult",
|
|
40
|
+
name="trace_id",
|
|
41
|
+
field=models.CharField(allow_null=True, max_length=34, required=False),
|
|
42
|
+
),
|
|
43
|
+
migrations.AddIndex(
|
|
44
|
+
model_name="job",
|
|
45
|
+
index=models.Index(
|
|
46
|
+
fields=["trace_id"], name="plainworker_trace_i_d2b645_idx"
|
|
47
|
+
),
|
|
48
|
+
),
|
|
49
|
+
migrations.AddIndex(
|
|
50
|
+
model_name="jobrequest",
|
|
51
|
+
index=models.Index(
|
|
52
|
+
fields=["trace_id"], name="plainworker_trace_i_e9dfc5_idx"
|
|
53
|
+
),
|
|
54
|
+
),
|
|
55
|
+
migrations.AddIndex(
|
|
56
|
+
model_name="jobresult",
|
|
57
|
+
index=models.Index(
|
|
58
|
+
fields=["trace_id"], name="plainworker_trace_i_00c75f_idx"
|
|
59
|
+
),
|
|
60
|
+
),
|
|
61
|
+
]
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Generated by Plain 0.63.0 on 2025-09-15 21:29
|
|
2
|
+
|
|
3
|
+
from plain import models
|
|
4
|
+
from plain.models import migrations
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Migration(migrations.Migration):
|
|
8
|
+
dependencies = [
|
|
9
|
+
("plainjobs", "0002_job_span_id_job_trace_id_jobrequest_span_id_and_more"),
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
operations = [
|
|
13
|
+
migrations.RenameModel(
|
|
14
|
+
old_name="Job",
|
|
15
|
+
new_name="JobProcess",
|
|
16
|
+
),
|
|
17
|
+
migrations.RemoveIndex(
|
|
18
|
+
model_name="jobresult",
|
|
19
|
+
name="plainworker_job_uui_8307d1_idx",
|
|
20
|
+
),
|
|
21
|
+
migrations.RenameField(
|
|
22
|
+
model_name="jobresult",
|
|
23
|
+
old_name="job_uuid",
|
|
24
|
+
new_name="job_process_uuid",
|
|
25
|
+
),
|
|
26
|
+
migrations.RenameIndex(
|
|
27
|
+
model_name="jobprocess",
|
|
28
|
+
new_name="plainworker_created_0d3928_idx",
|
|
29
|
+
old_name="plainworker_created_a02317_idx",
|
|
30
|
+
),
|
|
31
|
+
migrations.RenameIndex(
|
|
32
|
+
model_name="jobprocess",
|
|
33
|
+
new_name="plainworker_queue_2550ba_idx",
|
|
34
|
+
old_name="plainworker_queue_077806_idx",
|
|
35
|
+
),
|
|
36
|
+
migrations.RenameIndex(
|
|
37
|
+
model_name="jobprocess",
|
|
38
|
+
new_name="plainworker_unique__9dc0bb_idx",
|
|
39
|
+
old_name="plainworker_unique__04d87b_idx",
|
|
40
|
+
),
|
|
41
|
+
migrations.RenameIndex(
|
|
42
|
+
model_name="jobprocess",
|
|
43
|
+
new_name="plainworker_started_b80ec5_idx",
|
|
44
|
+
old_name="plainworker_started_143df5_idx",
|
|
45
|
+
),
|
|
46
|
+
migrations.RenameIndex(
|
|
47
|
+
model_name="jobprocess",
|
|
48
|
+
new_name="plainworker_job_cla_fe2b70_idx",
|
|
49
|
+
old_name="plainworker_job_cla_884b46_idx",
|
|
50
|
+
),
|
|
51
|
+
migrations.RenameIndex(
|
|
52
|
+
model_name="jobprocess",
|
|
53
|
+
new_name="plainworker_job_req_357898_idx",
|
|
54
|
+
old_name="plainworker_job_req_db2681_idx",
|
|
55
|
+
),
|
|
56
|
+
migrations.RenameIndex(
|
|
57
|
+
model_name="jobprocess",
|
|
58
|
+
new_name="plainworker_trace_i_da2cfa_idx",
|
|
59
|
+
old_name="plainworker_trace_i_d2b645_idx",
|
|
60
|
+
),
|
|
61
|
+
migrations.AddIndex(
|
|
62
|
+
model_name="jobresult",
|
|
63
|
+
index=models.Index(
|
|
64
|
+
fields=["job_process_uuid"], name="plainworker_job_pro_ceabfb_idx"
|
|
65
|
+
),
|
|
66
|
+
),
|
|
67
|
+
# To fix subsequent migrations...
|
|
68
|
+
migrations.AlterModelTable(
|
|
69
|
+
name="JobRequest",
|
|
70
|
+
table="plainworker_jobrequest",
|
|
71
|
+
),
|
|
72
|
+
migrations.AlterModelTable(
|
|
73
|
+
name="JobProcess",
|
|
74
|
+
table="plainworker_jobprocess",
|
|
75
|
+
),
|
|
76
|
+
migrations.AlterModelTable(
|
|
77
|
+
name="JobResult",
|
|
78
|
+
table="plainworker_jobresult",
|
|
79
|
+
),
|
|
80
|
+
]
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Manual transition from plain-worker (plainworker) to plain-jobs (plainjobs)
|
|
2
|
+
#
|
|
3
|
+
# If upgrading from plain.worker, run this SQL command BEFORE running migrations:
|
|
4
|
+
#
|
|
5
|
+
# plain db shell -- -c "INSERT INTO plainmigrations (app, name, applied) SELECT 'plainjobs', name, applied FROM plainmigrations WHERE app = 'plainworker' ON CONFLICT DO NOTHING;"
|
|
6
|
+
#
|
|
7
|
+
# Then run: plain migrate
|
|
8
|
+
# Then run: plain migrations prune (to clean up old plainworker records)
|
|
9
|
+
#
|
|
10
|
+
# Step 1: Rename tables from plainworker_* to plainjobs_*
|
|
11
|
+
|
|
12
|
+
from plain.models import migrations
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Migration(migrations.Migration):
|
|
16
|
+
dependencies = [
|
|
17
|
+
("plainjobs", "0003_rename_job_jobprocess_and_more"),
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
operations = [
|
|
21
|
+
migrations.AlterModelTable(
|
|
22
|
+
name="JobRequest",
|
|
23
|
+
table="plainjobs_jobrequest",
|
|
24
|
+
),
|
|
25
|
+
migrations.AlterModelTable(
|
|
26
|
+
name="JobProcess",
|
|
27
|
+
table="plainjobs_jobprocess",
|
|
28
|
+
),
|
|
29
|
+
migrations.AlterModelTable(
|
|
30
|
+
name="JobResult",
|
|
31
|
+
table="plainjobs_jobresult",
|
|
32
|
+
),
|
|
33
|
+
]
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# Step 2: Rename constraints and indexes from plainworker_* to plainjobs_*
|
|
2
|
+
# (Tables were renamed to plainjobs_* in migration 0004)
|
|
3
|
+
|
|
4
|
+
from plain import models
|
|
5
|
+
from plain.models import migrations
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Migration(migrations.Migration):
|
|
9
|
+
dependencies = [
|
|
10
|
+
("plainjobs", "0004_rename_tables_to_plainjobs"),
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
operations = [
|
|
14
|
+
# Remove old constraints (on plainjobs_* tables now)
|
|
15
|
+
migrations.RemoveConstraint(
|
|
16
|
+
model_name="jobprocess",
|
|
17
|
+
name="plainworker_job_unique_uuid",
|
|
18
|
+
),
|
|
19
|
+
migrations.RemoveConstraint(
|
|
20
|
+
model_name="jobrequest",
|
|
21
|
+
name="plainworker_jobrequest_unique_job_class_key",
|
|
22
|
+
),
|
|
23
|
+
migrations.RemoveConstraint(
|
|
24
|
+
model_name="jobrequest",
|
|
25
|
+
name="plainworker_jobrequest_unique_uuid",
|
|
26
|
+
),
|
|
27
|
+
migrations.RemoveConstraint(
|
|
28
|
+
model_name="jobresult",
|
|
29
|
+
name="plainworker_jobresult_unique_uuid",
|
|
30
|
+
),
|
|
31
|
+
# Rename indexes
|
|
32
|
+
migrations.RenameIndex(
|
|
33
|
+
model_name="jobprocess",
|
|
34
|
+
new_name="plainjobs_j_created_04fbb8_idx",
|
|
35
|
+
old_name="plainworker_created_0d3928_idx",
|
|
36
|
+
),
|
|
37
|
+
migrations.RenameIndex(
|
|
38
|
+
model_name="jobprocess",
|
|
39
|
+
new_name="plainjobs_j_queue_d07d21_idx",
|
|
40
|
+
old_name="plainworker_queue_2550ba_idx",
|
|
41
|
+
),
|
|
42
|
+
migrations.RenameIndex(
|
|
43
|
+
model_name="jobprocess",
|
|
44
|
+
new_name="plainjobs_j_unique__67172c_idx",
|
|
45
|
+
old_name="plainworker_unique__9dc0bb_idx",
|
|
46
|
+
),
|
|
47
|
+
migrations.RenameIndex(
|
|
48
|
+
model_name="jobprocess",
|
|
49
|
+
new_name="plainjobs_j_started_5cd62a_idx",
|
|
50
|
+
old_name="plainworker_started_b80ec5_idx",
|
|
51
|
+
),
|
|
52
|
+
migrations.RenameIndex(
|
|
53
|
+
model_name="jobprocess",
|
|
54
|
+
new_name="plainjobs_j_job_cla_19f3c1_idx",
|
|
55
|
+
old_name="plainworker_job_cla_fe2b70_idx",
|
|
56
|
+
),
|
|
57
|
+
migrations.RenameIndex(
|
|
58
|
+
model_name="jobprocess",
|
|
59
|
+
new_name="plainjobs_j_job_req_32b6eb_idx",
|
|
60
|
+
old_name="plainworker_job_req_357898_idx",
|
|
61
|
+
),
|
|
62
|
+
migrations.RenameIndex(
|
|
63
|
+
model_name="jobprocess",
|
|
64
|
+
new_name="plainjobs_j_trace_i_9f93c8_idx",
|
|
65
|
+
old_name="plainworker_trace_i_da2cfa_idx",
|
|
66
|
+
),
|
|
67
|
+
migrations.RenameIndex(
|
|
68
|
+
model_name="jobrequest",
|
|
69
|
+
new_name="plainjobs_j_priorit_fd4fac_idx",
|
|
70
|
+
old_name="plainworker_priorit_785e73_idx",
|
|
71
|
+
),
|
|
72
|
+
migrations.RenameIndex(
|
|
73
|
+
model_name="jobrequest",
|
|
74
|
+
new_name="plainjobs_j_created_1eeb20_idx",
|
|
75
|
+
old_name="plainworker_created_c81fe5_idx",
|
|
76
|
+
),
|
|
77
|
+
migrations.RenameIndex(
|
|
78
|
+
model_name="jobrequest",
|
|
79
|
+
new_name="plainjobs_j_queue_b34b5a_idx",
|
|
80
|
+
old_name="plainworker_queue_2614aa_idx",
|
|
81
|
+
),
|
|
82
|
+
migrations.RenameIndex(
|
|
83
|
+
model_name="jobrequest",
|
|
84
|
+
new_name="plainjobs_j_start_a_f3b8da_idx",
|
|
85
|
+
old_name="plainworker_start_a_4d6020_idx",
|
|
86
|
+
),
|
|
87
|
+
migrations.RenameIndex(
|
|
88
|
+
model_name="jobrequest",
|
|
89
|
+
new_name="plainjobs_j_unique__42f6a6_idx",
|
|
90
|
+
old_name="plainworker_unique__21a534_idx",
|
|
91
|
+
),
|
|
92
|
+
migrations.RenameIndex(
|
|
93
|
+
model_name="jobrequest",
|
|
94
|
+
new_name="plainjobs_j_job_cla_a18abf_idx",
|
|
95
|
+
old_name="plainworker_job_cla_3e7dea_idx",
|
|
96
|
+
),
|
|
97
|
+
migrations.RenameIndex(
|
|
98
|
+
model_name="jobrequest",
|
|
99
|
+
new_name="plainjobs_j_trace_i_194003_idx",
|
|
100
|
+
old_name="plainworker_trace_i_e9dfc5_idx",
|
|
101
|
+
),
|
|
102
|
+
migrations.RenameIndex(
|
|
103
|
+
model_name="jobresult",
|
|
104
|
+
new_name="plainjobs_j_created_7978bf_idx",
|
|
105
|
+
old_name="plainworker_created_6894c5_idx",
|
|
106
|
+
),
|
|
107
|
+
migrations.RenameIndex(
|
|
108
|
+
model_name="jobresult",
|
|
109
|
+
new_name="plainjobs_j_job_pro_751a64_idx",
|
|
110
|
+
old_name="plainworker_job_pro_ceabfb_idx",
|
|
111
|
+
),
|
|
112
|
+
migrations.RenameIndex(
|
|
113
|
+
model_name="jobresult",
|
|
114
|
+
new_name="plainjobs_j_started_6fb2ce_idx",
|
|
115
|
+
old_name="plainworker_started_9bce76_idx",
|
|
116
|
+
),
|
|
117
|
+
migrations.RenameIndex(
|
|
118
|
+
model_name="jobresult",
|
|
119
|
+
new_name="plainjobs_j_ended_a_648f25_idx",
|
|
120
|
+
old_name="plainworker_ended_a_63caaf_idx",
|
|
121
|
+
),
|
|
122
|
+
migrations.RenameIndex(
|
|
123
|
+
model_name="jobresult",
|
|
124
|
+
new_name="plainjobs_j_status_1ef683_idx",
|
|
125
|
+
old_name="plainworker_status_a7ca35_idx",
|
|
126
|
+
),
|
|
127
|
+
migrations.RenameIndex(
|
|
128
|
+
model_name="jobresult",
|
|
129
|
+
new_name="plainjobs_j_job_req_3ddecf_idx",
|
|
130
|
+
old_name="plainworker_job_req_1e1bf2_idx",
|
|
131
|
+
),
|
|
132
|
+
migrations.RenameIndex(
|
|
133
|
+
model_name="jobresult",
|
|
134
|
+
new_name="plainjobs_j_job_cla_8791b4_idx",
|
|
135
|
+
old_name="plainworker_job_cla_d138b5_idx",
|
|
136
|
+
),
|
|
137
|
+
migrations.RenameIndex(
|
|
138
|
+
model_name="jobresult",
|
|
139
|
+
new_name="plainjobs_j_queue_0a2178_idx",
|
|
140
|
+
old_name="plainworker_queue_23d8fe_idx",
|
|
141
|
+
),
|
|
142
|
+
migrations.RenameIndex(
|
|
143
|
+
model_name="jobresult",
|
|
144
|
+
new_name="plainjobs_j_trace_i_02f370_idx",
|
|
145
|
+
old_name="plainworker_trace_i_00c75f_idx",
|
|
146
|
+
),
|
|
147
|
+
# Add new constraints (on plainworker_* tables, but with new names)
|
|
148
|
+
migrations.AddConstraint(
|
|
149
|
+
model_name="jobprocess",
|
|
150
|
+
constraint=models.UniqueConstraint(
|
|
151
|
+
fields=("uuid",), name="plainjobs_job_unique_uuid"
|
|
152
|
+
),
|
|
153
|
+
),
|
|
154
|
+
migrations.AddConstraint(
|
|
155
|
+
model_name="jobrequest",
|
|
156
|
+
constraint=models.UniqueConstraint(
|
|
157
|
+
condition=models.Q(("retry_attempt", 0), ("unique_key__gt", "")),
|
|
158
|
+
fields=("job_class", "unique_key"),
|
|
159
|
+
name="plainjobs_jobrequest_unique_job_class_key",
|
|
160
|
+
),
|
|
161
|
+
),
|
|
162
|
+
migrations.AddConstraint(
|
|
163
|
+
model_name="jobrequest",
|
|
164
|
+
constraint=models.UniqueConstraint(
|
|
165
|
+
fields=("uuid",), name="plainjobs_jobrequest_unique_uuid"
|
|
166
|
+
),
|
|
167
|
+
),
|
|
168
|
+
migrations.AddConstraint(
|
|
169
|
+
model_name="jobresult",
|
|
170
|
+
constraint=models.UniqueConstraint(
|
|
171
|
+
fields=("uuid",), name="plainjobs_jobresult_unique_uuid"
|
|
172
|
+
),
|
|
173
|
+
),
|
|
174
|
+
]
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Generated by Plain 0.74.0 on 2025-10-10 20:57
|
|
2
|
+
|
|
3
|
+
from plain.models import migrations
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Migration(migrations.Migration):
|
|
7
|
+
dependencies = [
|
|
8
|
+
("plainjobs", "0005_rename_constraints_and_indexes"),
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
operations = [
|
|
12
|
+
migrations.AlterModelTable(
|
|
13
|
+
name="jobprocess",
|
|
14
|
+
table=None,
|
|
15
|
+
),
|
|
16
|
+
migrations.AlterModelTable(
|
|
17
|
+
name="jobrequest",
|
|
18
|
+
table=None,
|
|
19
|
+
),
|
|
20
|
+
migrations.AlterModelTable(
|
|
21
|
+
name="jobresult",
|
|
22
|
+
table=None,
|
|
23
|
+
),
|
|
24
|
+
]
|