openaleph_procrastinate.model
MAX_LOCK_KEY = 256
module-attribute
Length up to which a queueing lock spells out the entity ids it covers
DatasetJob
Bases: Job
A job with arbitrary payload bound to a dataset.
The payload always contains an iterable of serialized EntityProxy objects
in the entities key. It may contain other payload context data in the
context key.
There are helpers for accessing archive files or loading entities.
Source code in openaleph_procrastinate/model.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |
from_entities(dataset, queue, task, entities, dehydrate=settings.procrastinate_dehydrate_entities, **context)
classmethod
Make a job to process entities for a dataset
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
str
|
Name of the dataset |
required |
queue
|
str
|
Name of the queue |
required |
task
|
str
|
Python module path of the task |
required |
entities
|
Iterable[EntityProxy]
|
Entities |
required |
dehydrate
|
bool
|
Reduce entity payload to only a reference (tasks should
re-fetch these entities from the store if they need more data).
Ignored when |
procrastinate_dehydrate_entities
|
context
|
Any
|
Job context |
{}
|
Source code in openaleph_procrastinate/model.py
get_entities()
Get the entities from the payload
Source code in openaleph_procrastinate/model.py
get_file_references()
Get file references per entity from this job
Example
# process temporary file paths
for reference in job.get_file_references():
with reference.get_local_path() as path:
subprocess.run(["command", "-i", str(path)])
# temporary path will be cleaned up when leaving context
# process temporary file handlers
for reference in job.get_file_references():
with reference.open() as handler:
do_something(handler.read())
# temporary path will be cleaned up when leaving context
Yields:
| Type | Description |
|---|---|
EntityFileReference
|
The file references |
Source code in openaleph_procrastinate/model.py
get_queueing_lock()
A lock that identifies this job by its task, dataset and entities, so
procrastinate can collapse it with an identical job that is still
waiting. None when the payload carries no entities to key on.
Returns:
| Type | Description |
|---|---|
str | None
|
The queueing lock |
Source code in openaleph_procrastinate/model.py
get_writer(origin=helpers.OPAL_ORIGIN)
Get the writer for the dataset of the current job
load_entities()
Load the entities from the store to refresh it to the latest data
Source code in openaleph_procrastinate/model.py
EntityFileReference
Bases: BaseModel
A file reference (via content_hash) from an entity to a file in the
archive
Source code in openaleph_procrastinate/model.py
get_localpath()
Job
Bases: JobModel
A job with arbitrary payload
Source code in openaleph_procrastinate/model.py
context
property
Get the context from the payload if any
defer(app, priority=None, queueing_lock=None)
Defer this job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
App
|
The procrastinate app instance |
required |
priority
|
int | None
|
Job priority |
None
|
queueing_lock
|
str | None
|
Refuse the job while one with the same lock is still waiting in the queue |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
Whether the job was deferred |
Source code in openaleph_procrastinate/model.py
JobModel
Bases: BaseModel
A job with arbitrary payload