labtasker-client 2.6.0__tar.gz → 2.8.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 (25) hide show
  1. {labtasker_client-2.6.0 → labtasker_client-2.8.0}/PKG-INFO +1 -1
  2. {labtasker_client-2.6.0 → labtasker_client-2.8.0}/pyproject.toml +1 -1
  3. {labtasker_client-2.6.0 → labtasker_client-2.8.0}/src/labtasker/__init__.py +1 -1
  4. {labtasker_client-2.6.0 → labtasker_client-2.8.0}/src/labtasker/api.py +18 -2
  5. {labtasker_client-2.6.0 → labtasker_client-2.8.0}/src/labtasker/cli.py +22 -0
  6. {labtasker_client-2.6.0 → labtasker_client-2.8.0}/src/labtasker/client.py +25 -1
  7. {labtasker_client-2.6.0 → labtasker_client-2.8.0}/src/labtasker/command_worker.py +4 -2
  8. {labtasker_client-2.6.0 → labtasker_client-2.8.0}/src/labtasker/models.py +8 -0
  9. {labtasker_client-2.6.0 → labtasker_client-2.8.0}/src/labtasker/types.py +2 -0
  10. {labtasker_client-2.6.0 → labtasker_client-2.8.0}/src/labtasker/validation.py +24 -2
  11. {labtasker_client-2.6.0 → labtasker_client-2.8.0}/.gitignore +0 -0
  12. {labtasker_client-2.6.0 → labtasker_client-2.8.0}/LICENSE +0 -0
  13. {labtasker_client-2.6.0 → labtasker_client-2.8.0}/src/labtasker/__main__.py +0 -0
  14. {labtasker_client-2.6.0 → labtasker_client-2.8.0}/src/labtasker/binding.py +0 -0
  15. {labtasker_client-2.6.0 → labtasker_client-2.8.0}/src/labtasker/command_template.py +0 -0
  16. {labtasker_client-2.6.0 → labtasker_client-2.8.0}/src/labtasker/config.py +0 -0
  17. {labtasker_client-2.6.0 → labtasker_client-2.8.0}/src/labtasker/errors.py +0 -0
  18. {labtasker_client-2.6.0 → labtasker_client-2.8.0}/src/labtasker/execution.py +0 -0
  19. {labtasker_client-2.6.0 → labtasker_client-2.8.0}/src/labtasker/journal.py +0 -0
  20. {labtasker_client-2.6.0 → labtasker_client-2.8.0}/src/labtasker/local.py +0 -0
  21. {labtasker_client-2.6.0 → labtasker_client-2.8.0}/src/labtasker/observations.py +0 -0
  22. {labtasker_client-2.6.0 → labtasker_client-2.8.0}/src/labtasker/paths.py +0 -0
  23. {labtasker_client-2.6.0 → labtasker_client-2.8.0}/src/labtasker/py.typed +0 -0
  24. {labtasker_client-2.6.0 → labtasker_client-2.8.0}/src/labtasker/tee.py +0 -0
  25. {labtasker_client-2.6.0 → labtasker_client-2.8.0}/src/labtasker/worker.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: labtasker-client
3
- Version: 2.6.0
3
+ Version: 2.8.0
4
4
  Summary: A small task queue for parallel model inference and evaluation
5
5
  Project-URL: Homepage, https://github.com/luocfprime/labtasker
6
6
  Project-URL: Repository, https://github.com/luocfprime/labtasker.git
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "labtasker-client"
7
- version = "2.6.0"
7
+ version = "2.8.0"
8
8
  description = "A small task queue for parallel model inference and evaluation"
9
9
  requires-python = ">=3.10"
10
10
  license = "Apache-2.0"
@@ -50,7 +50,7 @@ from labtasker.models import (
50
50
  from labtasker.types import JSONValue, TaskOrderField, TaskStatus, TaskUpdate
51
51
  from labtasker.worker import loop
52
52
 
53
- __version__ = "2.6.0"
53
+ __version__ = "2.8.0"
54
54
 
55
55
  __all__ = [
56
56
  "APIError",
@@ -20,6 +20,7 @@ def submit_task(
20
20
  priority: int = 0,
21
21
  max_attempts: int = 3,
22
22
  routes: list[str] | None = None,
23
+ dependencies: list[str] | None = None,
23
24
  task_id: str | None = None,
24
25
  queue: str | None = None,
25
26
  ) -> Task:
@@ -30,6 +31,7 @@ def submit_task(
30
31
  priority=priority,
31
32
  max_attempts=max_attempts,
32
33
  routes=routes,
34
+ dependencies=dependencies,
33
35
  task_id=task_id,
34
36
  queue=queue,
35
37
  )
@@ -41,6 +43,7 @@ def get_task(task_id: str, *, queue: str | None = None) -> Task:
41
43
 
42
44
  def list_tasks(
43
45
  *,
46
+ include_archived: bool = False,
44
47
  status: TaskStatus | None = None,
45
48
  name: str | None = None,
46
49
  name_fuzzy: str | None = None,
@@ -53,6 +56,7 @@ def list_tasks(
53
56
  ) -> TaskPage:
54
57
  return _client().list_tasks(
55
58
  status=status,
59
+ include_archived=include_archived,
56
60
  name=name,
57
61
  name_fuzzy=name_fuzzy,
58
62
  filter=filter,
@@ -67,6 +71,7 @@ def list_tasks(
67
71
  @overload
68
72
  def count_tasks(
69
73
  *,
74
+ include_archived: bool = False,
70
75
  status: TaskStatus | None = None,
71
76
  name: str | None = None,
72
77
  name_fuzzy: str | None = None,
@@ -81,6 +86,7 @@ def count_tasks(
81
86
  @overload
82
87
  def count_tasks(
83
88
  *,
89
+ include_archived: bool = False,
84
90
  status: TaskStatus | None = None,
85
91
  name: str | None = None,
86
92
  name_fuzzy: str | None = None,
@@ -94,6 +100,7 @@ def count_tasks(
94
100
 
95
101
  def count_tasks(
96
102
  *,
103
+ include_archived: bool = False,
97
104
  status: TaskStatus | None = None,
98
105
  name: str | None = None,
99
106
  name_fuzzy: str | None = None,
@@ -109,10 +116,16 @@ def count_tasks(
109
116
 
110
117
  validate_grouping(None, {"routes", "status"}, limit, cursor)
111
118
  return _client().count_tasks(
112
- status=status, name=name, name_fuzzy=name_fuzzy, filter=filter, queue=queue
119
+ status=status,
120
+ name=name,
121
+ name_fuzzy=name_fuzzy,
122
+ filter=filter,
123
+ queue=queue,
124
+ include_archived=include_archived,
113
125
  )
114
126
  return _client().count_tasks(
115
127
  status=status,
128
+ include_archived=include_archived,
116
129
  name=name,
117
130
  name_fuzzy=name_fuzzy,
118
131
  filter=filter,
@@ -179,11 +192,14 @@ def update_task(
179
192
 
180
193
  def update_tasks(
181
194
  *,
195
+ include_archived: bool = False,
182
196
  filter: str,
183
197
  changes: TaskUpdate,
184
198
  queue: str | None = None,
185
199
  ) -> BulkUpdateResult:
186
- return _client().update_tasks(filter=filter, changes=changes, queue=queue)
200
+ return _client().update_tasks(
201
+ filter=filter, changes=changes, queue=queue, include_archived=include_archived
202
+ )
187
203
 
188
204
 
189
205
  def cancel_task(task_id: str, *, queue: str | None = None) -> Task:
@@ -231,6 +231,13 @@ def task_submit(
231
231
  str | None,
232
232
  typer.Option("--id", help="Caller-chosen idempotent Task ID."),
233
233
  ] = None,
234
+ dependencies: Annotated[
235
+ list[str] | None,
236
+ typer.Option(
237
+ "--dependency",
238
+ help="Experimental: same-Queue Task ID required to succeed; repeat as needed.",
239
+ ),
240
+ ] = None,
234
241
  queue: Annotated[
235
242
  str | None,
236
243
  typer.Option(help="Target Queue; otherwise use Client configuration."),
@@ -257,6 +264,7 @@ def task_submit(
257
264
  priority=priority,
258
265
  max_attempts=max_attempts,
259
266
  routes=routes,
267
+ dependencies=dependencies,
260
268
  task_id=task_id,
261
269
  queue=queue,
262
270
  )
@@ -311,6 +319,9 @@ def task_list(
311
319
  str | None,
312
320
  typer.Option(help="Opaque next_cursor from the same query and ordering."),
313
321
  ] = None,
322
+ include_archived: Annotated[
323
+ bool, typer.Option("--include-archived", help="Include archived Tasks in the filter range.")
324
+ ] = False,
314
325
  queue: Annotated[
315
326
  str | None,
316
327
  typer.Option(help="Task Queue; otherwise use Client configuration."),
@@ -332,6 +343,7 @@ def task_list(
332
343
  lambda: _with_client(
333
344
  lambda client: client.list_tasks(
334
345
  status=status,
346
+ include_archived=include_archived,
335
347
  name=name,
336
348
  name_fuzzy=name_fuzzy,
337
349
  filter=filter,
@@ -383,6 +395,9 @@ def task_count(
383
395
  cursor: Annotated[
384
396
  str | None, typer.Option(help="Next group page cursor; requires --group-by.")
385
397
  ] = None,
398
+ include_archived: Annotated[
399
+ bool, typer.Option("--include-archived", help="Include archived Tasks in the filter range.")
400
+ ] = False,
386
401
  queue: Annotated[
387
402
  str | None,
388
403
  typer.Option(help="Task Queue; otherwise use Client configuration."),
@@ -401,6 +416,7 @@ def task_count(
401
416
  lambda: _with_client(
402
417
  lambda client: client.count_tasks(
403
418
  status=status,
419
+ include_archived=include_archived,
404
420
  name=name,
405
421
  name_fuzzy=name_fuzzy,
406
422
  filter=filter,
@@ -499,6 +515,9 @@ def task_update(
499
515
  str,
500
516
  typer.Option(help="Fields to replace as one strict JSON object."),
501
517
  ] = "",
518
+ include_archived: Annotated[
519
+ bool, typer.Option("--include-archived", help="Include archived Tasks in the filter range.")
520
+ ] = False,
502
521
  queue: Annotated[
503
522
  str | None,
504
523
  typer.Option(help="Task Queue; otherwise use Client configuration."),
@@ -520,6 +539,8 @@ def task_update(
520
539
  """
521
540
  if (task_id is None) == (filter is None):
522
541
  raise typer.BadParameter("provide exactly one of TASK_ID or --filter")
542
+ if task_id is not None and include_archived:
543
+ raise typer.BadParameter("--include-archived requires --filter")
523
544
  if not changes:
524
545
  raise typer.BadParameter("--changes is required")
525
546
  normalized = cast(TaskUpdate, _json_object(changes, option="--changes"))
@@ -535,6 +556,7 @@ def task_update(
535
556
  lambda: _with_client(
536
557
  lambda client: client.update_tasks(
537
558
  filter=filter or "",
559
+ include_archived=include_archived,
538
560
  changes=normalized,
539
561
  queue=queue,
540
562
  )
@@ -30,6 +30,7 @@ from labtasker.models import (
30
30
  from labtasker.types import JSONValue, TaskOrderField, TaskStatus, TaskUpdate
31
31
  from labtasker.validation import (
32
32
  RequestValidationError,
33
+ validate_dependencies,
33
34
  validate_filter,
34
35
  validate_grouping,
35
36
  validate_identifier,
@@ -170,6 +171,7 @@ class Client:
170
171
  priority: int = 0,
171
172
  max_attempts: int = 3,
172
173
  routes: list[str] | None = None,
174
+ dependencies: list[str] | None = None,
173
175
  task_id: str | None = None,
174
176
  queue: str | None = None,
175
177
  ) -> Task:
@@ -180,6 +182,9 @@ class Client:
180
182
  field="metadata",
181
183
  )
182
184
  normalized_routes = validate_routes(["default"] if routes is None else routes)
185
+ normalized_dependencies = validate_dependencies(
186
+ [] if dependencies is None else dependencies
187
+ )
183
188
  body: dict[str, object] = {
184
189
  "name": validate_task_name(name),
185
190
  "args": normalized_args,
@@ -192,6 +197,8 @@ class Client:
192
197
  ),
193
198
  "routes": normalized_routes,
194
199
  }
200
+ if normalized_dependencies:
201
+ body["dependencies"] = normalized_dependencies
195
202
  queue_name = self._queue(queue)
196
203
  if task_id is not None:
197
204
  selected_id = validate_task_id(task_id)
@@ -224,6 +231,7 @@ class Client:
224
231
  def list_tasks(
225
232
  self,
226
233
  *,
234
+ include_archived: bool = False,
227
235
  status: TaskStatus | None = None,
228
236
  name: str | None = None,
229
237
  name_fuzzy: str | None = None,
@@ -234,6 +242,8 @@ class Client:
234
242
  cursor: str | None = None,
235
243
  queue: str | None = None,
236
244
  ) -> TaskPage:
245
+ if not isinstance(include_archived, bool):
246
+ raise RequestValidationError("include_archived must be a Boolean.")
237
247
  self._ensure_open()
238
248
  queue_name = self._queue(queue)
239
249
  status = validate_status(status)
@@ -257,6 +267,7 @@ class Client:
257
267
  validate_unicode_scalar(cursor, field="cursor")
258
268
  params = _without_none(
259
269
  {
270
+ **({"include_archived": "true"} if include_archived else {}),
260
271
  "status": status,
261
272
  "name": name,
262
273
  "name_fuzzy": name_fuzzy,
@@ -280,6 +291,7 @@ class Client:
280
291
  def count_tasks(
281
292
  self,
282
293
  *,
294
+ include_archived: bool = False,
283
295
  status: TaskStatus | None = None,
284
296
  name: str | None = None,
285
297
  name_fuzzy: str | None = None,
@@ -294,6 +306,7 @@ class Client:
294
306
  def count_tasks(
295
307
  self,
296
308
  *,
309
+ include_archived: bool = False,
297
310
  status: TaskStatus | None = None,
298
311
  name: str | None = None,
299
312
  name_fuzzy: str | None = None,
@@ -307,6 +320,7 @@ class Client:
307
320
  def count_tasks(
308
321
  self,
309
322
  *,
323
+ include_archived: bool = False,
310
324
  status: TaskStatus | None = None,
311
325
  name: str | None = None,
312
326
  name_fuzzy: str | None = None,
@@ -316,6 +330,8 @@ class Client:
316
330
  limit: int | None = None,
317
331
  cursor: str | None = None,
318
332
  ) -> int | GroupCountPage:
333
+ if not isinstance(include_archived, bool):
334
+ raise RequestValidationError("include_archived must be a Boolean.")
319
335
  self._ensure_open()
320
336
  queue_name = self._queue(queue)
321
337
  status = validate_status(status)
@@ -335,6 +351,7 @@ class Client:
335
351
  groups,
336
352
  _without_none(
337
353
  {
354
+ **({"include_archived": "true"} if include_archived else {}),
338
355
  "status": status,
339
356
  "name": name,
340
357
  "name_fuzzy": name_fuzzy,
@@ -464,10 +481,13 @@ class Client:
464
481
  def update_tasks(
465
482
  self,
466
483
  *,
484
+ include_archived: bool = False,
467
485
  filter: str,
468
486
  changes: TaskUpdate,
469
487
  queue: str | None = None,
470
488
  ) -> BulkUpdateResult:
489
+ if not isinstance(include_archived, bool):
490
+ raise RequestValidationError("include_archived must be a Boolean.")
471
491
  self._ensure_open()
472
492
  queue_name = self._queue(queue)
473
493
  normalized_filter = validate_filter(filter, required=True)
@@ -476,7 +496,11 @@ class Client:
476
496
  operation="update_tasks",
477
497
  method="PATCH",
478
498
  path=f"queues/{queue_name}/tasks",
479
- json={"filter": normalized_filter, "changes": normalized_changes},
499
+ json={
500
+ "filter": normalized_filter,
501
+ "changes": normalized_changes,
502
+ **({"include_archived": True} if include_archived else {}),
503
+ },
480
504
  parser=lambda response: _parse_model(response, BulkUpdateResult, {200}),
481
505
  )
482
506
 
@@ -422,8 +422,10 @@ def _terminate_process_group(
422
422
  # cooperative signal handler writes cleanup output before exiting.
423
423
  if drain_output is not None:
424
424
  drain_output()
425
- process.poll()
426
- if not _process_group_alive(process.pid):
425
+ # The launcher itself proves that its process group is still alive.
426
+ # Avoid the more expensive group scan until it exits; on Darwin that
427
+ # scan starts /bin/ps and can otherwise starve PTY drainage.
428
+ if process.poll() is not None and not _process_group_alive(process.pid):
427
429
  break
428
430
  if deadline is not None and time.monotonic() >= deadline:
429
431
  _signal_process_group(process.pid, signal.SIGKILL)
@@ -8,6 +8,7 @@ from pydantic import BaseModel, ConfigDict, Field, field_validator, model_valida
8
8
 
9
9
  from labtasker.types import JSONValue, TaskStatus
10
10
  from labtasker.validation import (
11
+ validate_dependencies,
11
12
  validate_identifier,
12
13
  validate_int64,
13
14
  validate_json_object,
@@ -60,6 +61,7 @@ class Task(ResponseModel):
60
61
  id: str
61
62
  queue: str
62
63
  status: TaskStatus
64
+ archived: bool = False
63
65
  name: str | None
64
66
  args: dict[str, JSONValue]
65
67
  metadata: dict[str, JSONValue]
@@ -67,6 +69,7 @@ class Task(ResponseModel):
67
69
  attempt: int
68
70
  max_attempts: int
69
71
  routes: list[str]
72
+ dependencies: list[str] = Field(default_factory=list)
70
73
  result: dict[str, JSONValue]
71
74
  progress: dict[str, JSONValue] | None = None
72
75
  progress_updated_at: datetime | None = None
@@ -78,6 +81,11 @@ class Task(ResponseModel):
78
81
  started_at: datetime | None
79
82
  finished_at: datetime | None
80
83
 
84
+ @field_validator("dependencies")
85
+ @classmethod
86
+ def validate_task_dependencies(cls, value: list[str]) -> list[str]:
87
+ return validate_dependencies(value)
88
+
81
89
  @field_validator("id")
82
90
  @classmethod
83
91
  def validate_id(cls, value: str) -> str:
@@ -22,10 +22,12 @@ TaskOrderField: TypeAlias = Literal[
22
22
 
23
23
 
24
24
  class TaskUpdate(TypedDict, total=False):
25
+ archived: bool
25
26
  name: str | None
26
27
  args: dict[str, JSONValue]
27
28
  metadata: dict[str, JSONValue]
28
29
  priority: int
29
30
  max_attempts: int
30
31
  routes: list[str]
32
+ dependencies: list[str]
31
33
  result: dict[str, JSONValue]
@@ -120,6 +120,12 @@ def validate_run_id(value: object) -> str:
120
120
  return value
121
121
 
122
122
 
123
+ def validate_dependencies(value: object) -> list[str]:
124
+ if not isinstance(value, list):
125
+ raise RequestValidationError("dependencies must be a list of Task IDs.")
126
+ return [validate_task_id(task_id) for task_id in value]
127
+
128
+
123
129
  def validate_task_name(value: object) -> str | None:
124
130
  if value is None:
125
131
  return None
@@ -181,13 +187,27 @@ def validate_order_field(value: object) -> TaskOrderField:
181
187
  def validate_task_update(changes: object) -> TaskUpdate:
182
188
  if not isinstance(changes, dict) or not changes:
183
189
  raise RequestValidationError("changes must be a non-empty object.")
184
- allowed = {"name", "args", "metadata", "priority", "max_attempts", "routes", "result"}
190
+ allowed = {
191
+ "archived",
192
+ "name",
193
+ "args",
194
+ "metadata",
195
+ "priority",
196
+ "max_attempts",
197
+ "routes",
198
+ "dependencies",
199
+ "result",
200
+ }
185
201
  unknown = set(changes) - allowed
186
202
  if unknown:
187
203
  raise RequestValidationError(f"changes contains unsupported fields: {sorted(unknown)!r}.")
188
204
  normalized: dict[str, object] = {}
189
205
  for field, value in changes.items():
190
- if field == "name":
206
+ if field == "archived":
207
+ if not isinstance(value, bool):
208
+ raise RequestValidationError("archived must be a Boolean.")
209
+ normalized[field] = value
210
+ elif field == "name":
191
211
  normalized[field] = validate_task_name(value)
192
212
  elif field in {"args", "metadata", "result"}:
193
213
  normalized[field] = validate_json_object(value, field=field)
@@ -197,6 +217,8 @@ def validate_task_update(changes: object) -> TaskUpdate:
197
217
  normalized[field] = validate_int64(value, field=field, positive=True)
198
218
  elif field == "routes":
199
219
  normalized[field] = validate_routes(value)
220
+ elif field == "dependencies":
221
+ normalized[field] = validate_dependencies(value)
200
222
  return cast(TaskUpdate, normalized)
201
223
 
202
224