-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenapi.yaml
More file actions
918 lines (887 loc) · 27.9 KB
/
Copy pathopenapi.yaml
File metadata and controls
918 lines (887 loc) · 27.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
openapi: 3.1.0
info:
title: Durable Execution API
description: |
A minimalistic durable task queue with retry, scheduling, event coordination,
checkpoints, and workflow tracking.
Based on: https://github.com/earendil-works/absurd
## Core Concepts
- **Queue**: A named channel that tasks are submitted to and claimed from.
- **Task**: The logical unit of work. Persists across retries.
- **Run**: A single attempt at executing a task. Workers interact with runs.
- **Checkpoint**: Persisted state keyed by (task_id, step_name) that survives across runs.
- **Event**: A named signal with a JSON payload for cross-workflow coordination.
- **Workflow Run**: A grouping/tracking entity for related tasks.
## Claim Semantics
Claiming atomically locks runs and starts a claim timeout. If the worker doesn't
complete or fail the run before the timeout, the run becomes claimable again.
## Wait-for-Event Flow
1. Worker calls wait-for-event on a run.
2. If the event already exists, the payload is returned immediately (200).
3. If the event doesn't exist, the run is put to sleep (202). The worker should
stop processing and go back to claiming new work.
4. When the event is emitted, the server wakes sleeping runs and makes them claimable.
5. If the timeout elapses first, the run is marked as timed out (408).
version: 1.0.0
servers:
- url: http://localhost:8080/api/v1
paths:
/queues:
get:
operationId: listQueues
summary: List all queues
tags: [Queues]
responses:
"200":
description: List of queues
content:
application/json:
schema:
type: object
required: [queues]
properties:
queues:
type: array
items:
type: object
required: [name, created_at]
properties:
name:
type: string
created_at:
type: string
format: date-time
cleanup:
$ref: "#/components/schemas/CleanupPolicy"
post:
operationId: createQueue
summary: Create a queue
tags: [Queues]
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [name]
properties:
name:
type: string
example: my_queue
cleanup:
$ref: "#/components/schemas/CleanupPolicy"
responses:
"201":
description: Queue created
content:
application/json:
schema:
type: object
required: [name, created_at]
properties:
name:
type: string
created_at:
type: string
format: date-time
cleanup:
$ref: "#/components/schemas/CleanupPolicy"
"409":
$ref: "#/components/responses/Conflict"
/queues/{queue_name}:
delete:
operationId: deleteQueue
summary: Delete a queue
description: |
Deletes a queue. Fails with 409 if the queue still has tasks.
tags: [Queues]
parameters:
- $ref: "#/components/parameters/QueueName"
responses:
"204":
description: Queue deleted
"404":
$ref: "#/components/responses/NotFound"
"409":
$ref: "#/components/responses/Conflict"
/queues/{queue_name}/stats:
get:
operationId: getQueueStats
summary: Get queue statistics
description: |
Returns counts of runs by status and the age of the oldest pending run.
Useful for monitoring consumer lag and alerting on queue buildup.
tags: [Queues]
parameters:
- $ref: "#/components/parameters/QueueName"
responses:
"200":
description: Queue stats
content:
application/json:
schema:
type: object
required: [queue_name, pending_runs, claimed_runs, completed_runs]
properties:
queue_name:
type: string
pending_runs:
type: integer
claimed_runs:
type: integer
completed_runs:
type: integer
oldest_pending_run_age_seconds:
type: number
nullable: true
description: |
Seconds since the oldest pending run was created. Null when
there are no pending runs. This is the key consumer lag metric.
"404":
$ref: "#/components/responses/NotFound"
/queues/{queue_name}/tasks:
post:
operationId: createTask
summary: Create a task
description: |
Creates a new task in the queue. Returns the task ID, run ID, and
workflow run ID.
tags: [Tasks]
parameters:
- $ref: "#/components/parameters/QueueName"
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/CreateTaskRequest"
responses:
"201":
description: Task created
content:
application/json:
schema:
type: object
required: [task_id, run_id]
properties:
task_id:
type: string
example: task_a1b2c3
run_id:
type: string
example: run_x9y8z7
workflow_run_id:
type: string
example: wfr_abc123
"400":
$ref: "#/components/responses/BadRequest"
/queues/{queue_name}/tasks/claim:
post:
operationId: claimTasks
summary: Claim tasks for processing
description: |
Claims up to `limit` tasks from the queue. Claimed tasks are locked for
`claim_timeout` seconds. If not completed or failed within that window,
they become claimable again. Returns an empty array if no tasks are available.
tags: [Tasks]
parameters:
- $ref: "#/components/parameters/QueueName"
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [limit, claim_timeout]
properties:
limit:
type: integer
minimum: 1
description: Maximum number of tasks to claim
example: 1
claim_timeout:
type: integer
minimum: 1
description: Seconds before the claim expires
example: 60
long_poll_seconds:
type: integer
minimum: 5
maximum: 30
description: |
Long-poll timeout in seconds. When set, the server holds the connection
open until tasks become available or the timeout elapses. Uses PostgreSQL
LISTEN/NOTIFY for near-instant wake-up when new runs are created.
example: 30
responses:
"200":
description: Tasks claimed (may be empty)
content:
application/json:
schema:
type: object
required: [tasks]
properties:
tasks:
type: array
items:
$ref: "#/components/schemas/ClaimedTask"
/runs:
get:
operationId: listRuns
summary: List runs
description: |
Lists runs with optional filters. Useful for inspecting all attempts for
a task and their error messages.
tags: [Runs]
parameters:
- name: task_id
in: query
required: false
schema:
type: string
description: Filter by task ID
- name: status
in: query
required: false
schema:
type: string
enum: [pending, claimed, completed, failed, sleeping]
description: Filter by run status
- name: cursor
in: query
required: false
schema:
type: string
description: Pagination cursor from a previous response
- name: limit
in: query
required: false
schema:
type: integer
minimum: 1
default: 50
description: Maximum number of runs to return
responses:
"200":
description: List of runs
content:
application/json:
schema:
type: object
required: [runs]
properties:
runs:
type: array
items:
$ref: "#/components/schemas/RunSummary"
next_cursor:
type: string
description: Pass as `cursor` to fetch the next page. Absent when there are no more results.
/runs/{run_id}/complete:
post:
operationId: completeRun
summary: Mark run as completed
tags: [Runs]
parameters:
- $ref: "#/components/parameters/RunId"
requestBody:
required: false
content:
application/json:
schema:
type: object
properties:
result:
description: Arbitrary result data
example: {"output": "processed", "records": 42}
responses:
"200":
description: Run completed
content:
application/json:
schema:
type: object
required: [run_id, status]
properties:
run_id:
type: string
status:
type: string
enum: [completed]
"404":
$ref: "#/components/responses/NotFound"
"409":
$ref: "#/components/responses/Conflict"
/runs/{run_id}/fail:
post:
operationId: failRun
summary: Mark run as failed
description: |
Marks a run as failed. If retries remain (based on max_attempts and
retry_strategy), a new run is scheduled automatically.
tags: [Runs]
parameters:
- $ref: "#/components/parameters/RunId"
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [error]
properties:
error:
type: string
description: Error message describing the failure
example: connection timeout to upstream service
responses:
"200":
description: Run failed
content:
application/json:
schema:
type: object
required: [run_id, status, attempt]
properties:
run_id:
type: string
status:
type: string
enum: [failed]
attempt:
type: integer
next_run_id:
type: string
description: Present if a retry was scheduled
next_attempt_at:
type: string
format: date-time
description: Present if a retry was scheduled
"404":
$ref: "#/components/responses/NotFound"
"409":
$ref: "#/components/responses/Conflict"
/runs/{run_id}/schedule:
post:
operationId: scheduleRun
summary: Schedule run for future execution
description: Schedules a run to become claimable at a future time.
tags: [Runs]
parameters:
- $ref: "#/components/parameters/RunId"
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [run_at]
properties:
run_at:
type: string
format: date-time
description: When the run should become claimable
example: "2026-02-14T10:10:00Z"
responses:
"200":
description: Run scheduled
content:
application/json:
schema:
type: object
required: [run_id, scheduled_at]
properties:
run_id:
type: string
scheduled_at:
type: string
format: date-time
"404":
$ref: "#/components/responses/NotFound"
/runs/{run_id}/wait-for-event:
post:
operationId: waitForEvent
summary: Sleep until event or timeout
description: |
Suspends a run until a named event arrives or the timeout elapses.
If the event already exists, returns immediately with the payload (200).
If not, the run is put to sleep (202) and the worker should stop processing.
The server re-queues the run when the event arrives or marks it timed out (408).
tags: [Runs]
parameters:
- $ref: "#/components/parameters/RunId"
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [event_name, timeout_seconds, task_id, step_name]
properties:
event_name:
type: string
example: data_ready
timeout_seconds:
type: integer
minimum: 1
example: 3600
task_id:
type: string
example: task_a1b2c3
step_name:
type: string
description: Used for idempotency across retries
example: waiting_step
responses:
"200":
description: Event already available
content:
application/json:
schema:
type: object
required: [status, payload]
properties:
status:
type: string
enum: [resolved]
payload:
description: The event payload
"202":
description: Run put to sleep until event arrives
content:
application/json:
schema:
type: object
required: [status, message]
properties:
status:
type: string
enum: [sleeping]
message:
type: string
"408":
description: Timeout elapsed, event never arrived
content:
application/json:
schema:
type: object
required: [status, message]
properties:
status:
type: string
enum: [timeout]
message:
type: string
"404":
$ref: "#/components/responses/NotFound"
/tasks/{task_id}/checkpoints/{step_name}:
put:
operationId: setCheckpoint
summary: Set checkpoint state
description: |
Persists state for a task at a named step. Checkpoints survive across
runs, allowing a retried task to resume from where it left off.
tags: [Checkpoints]
parameters:
- $ref: "#/components/parameters/TaskId"
- $ref: "#/components/parameters/StepName"
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [state, owner_run]
properties:
state:
description: Arbitrary state to persist
example: {"current_step": 5, "total_steps": 10}
owner_run:
type: string
description: The run setting this checkpoint
example: run_x9y8z7
extend_claim_by:
type: integer
minimum: 1
description: Extend the claim timeout by this many seconds
example: 60
responses:
"200":
description: Checkpoint set
content:
application/json:
schema:
type: object
required: [task_id, step_name, updated_at]
properties:
task_id:
type: string
step_name:
type: string
updated_at:
type: string
format: date-time
"404":
$ref: "#/components/responses/NotFound"
get:
operationId: getCheckpoint
summary: Get checkpoint state
tags: [Checkpoints]
parameters:
- $ref: "#/components/parameters/TaskId"
- $ref: "#/components/parameters/StepName"
responses:
"200":
description: Checkpoint found
content:
application/json:
schema:
type: object
required: [task_id, step_name, state, updated_at]
properties:
task_id:
type: string
step_name:
type: string
state:
description: The persisted state
updated_at:
type: string
format: date-time
"404":
$ref: "#/components/responses/NotFound"
/events:
post:
operationId: emitEvent
summary: Emit an event
description: |
Emits a named event with an optional payload. If any runs are sleeping
on this event name, they are woken up and made claimable again.
tags: [Events]
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [event_name]
properties:
event_name:
type: string
example: data_ready
payload:
description: Arbitrary event data
example: {"processed_data": "result", "timestamp": "2025-01-01T00:00:00Z"}
responses:
"201":
description: Event emitted
content:
application/json:
schema:
type: object
required: [event_id, event_name, created_at]
properties:
event_id:
type: string
example: evt_d4e5f6
event_name:
type: string
created_at:
type: string
format: date-time
/workflow-runs:
post:
operationId: createWorkflowRun
summary: Create a workflow run
description: |
Creates a tracking entity for a group of related tasks. Link tasks to
a workflow run by passing the workflow_run_id when creating tasks.
tags: [Workflow Runs]
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [workflow_name]
properties:
workflow_name:
type: string
example: data_pipeline
workflow_version:
type: string
example: "1.0.0"
inputs:
description: Arbitrary workflow inputs
example: {"source": "s3://bucket/data", "target": "warehouse"}
created_by:
type: string
example: pipeline_system
tags:
type: object
additionalProperties:
type: string
example: {"environment": "production", "priority": "high"}
responses:
"201":
description: Workflow run created
content:
application/json:
schema:
type: object
required: [workflow_run_id, workflow_name, status, created_at]
properties:
workflow_run_id:
type: string
example: wfr_abc123
workflow_name:
type: string
status:
type: string
enum: [pending]
created_at:
type: string
format: date-time
/workflow-runs/{workflow_run_id}:
patch:
operationId: updateWorkflowRun
summary: Update workflow run status
tags: [Workflow Runs]
parameters:
- name: workflow_run_id
in: path
required: true
schema:
type: string
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
status:
type: string
enum: [pending, running, completed, failed, canceled]
result:
description: Arbitrary result data
started_at:
type: string
format: date-time
completed_at:
type: string
format: date-time
responses:
"200":
description: Workflow run updated
content:
application/json:
schema:
type: object
required: [workflow_run_id, status, updated_at]
properties:
workflow_run_id:
type: string
status:
type: string
updated_at:
type: string
format: date-time
"404":
$ref: "#/components/responses/NotFound"
components:
parameters:
QueueName:
name: queue_name
in: path
required: true
schema:
type: string
RunId:
name: run_id
in: path
required: true
schema:
type: string
TaskId:
name: task_id
in: path
required: true
schema:
type: string
StepName:
name: step_name
in: path
required: true
schema:
type: string
schemas:
CreateTaskRequest:
type: object
required: [task_name]
properties:
task_name:
type: string
example: process_data
params:
description: Arbitrary task parameters
example: {"input": "data", "options": {"verbose": true}}
headers:
type: object
additionalProperties:
type: string
description: Arbitrary key-value metadata
example: {"priority": "high", "region": "us-east-1"}
retry_strategy:
$ref: "#/components/schemas/RetryStrategy"
max_attempts:
type: integer
minimum: 1
default: 1
example: 3
start_timeout:
type: integer
minimum: 0
description: |
Maximum seconds the task can wait in the queue before being claimed.
The task is canceled if not claimed within this window. 0 means no limit.
example: 3600
execution_timeout:
type: integer
minimum: 0
description: |
Maximum wall-clock seconds from task creation to completion.
The task is canceled if not completed within this window, regardless
of retries. This is distinct from claim_timeout, which limits how long
a single worker can hold a lease on a run.
example: 7200
workflow_run_id:
type: string
description: Link this task to an existing workflow run
RetryStrategy:
type: object
required: [kind, base_seconds]
properties:
kind:
type: string
enum: [exponential, fixed]
base_seconds:
type: number
minimum: 0
description: Base delay between retries in seconds
example: 30
factor:
type: number
minimum: 1
description: Multiplier per attempt (exponential only)
example: 2.0
max_seconds:
type: number
minimum: 0
description: Maximum delay between retries in seconds
example: 3600
ClaimedTask:
type: object
required: [run_id, task_id, attempt, task_name]
properties:
run_id:
type: string
example: run_x9y8z7
task_id:
type: string
example: task_a1b2c3
attempt:
type: integer
example: 1
task_name:
type: string
example: process_data
params:
description: Task parameters as provided when created
headers:
type: object
additionalProperties:
type: string
retry_strategy:
$ref: "#/components/schemas/RetryStrategy"
max_attempts:
type: integer
RunSummary:
type: object
required: [id, task_id, attempt, status, created_at]
properties:
id:
type: string
task_id:
type: string
attempt:
type: integer
status:
type: string
enum: [pending, claimed, completed, failed, sleeping]
error:
type: string
description: Error message (present only for failed runs)
created_at:
type: string
format: date-time
completed_at:
type: string
format: date-time
CleanupPolicy:
type: object
description: |
Configures automatic background cleanup for completed tasks and events.
The server periodically deletes records older than the TTL.
properties:
task_ttl_seconds:
type: integer
minimum: 0
description: Delete completed tasks older than this many seconds. 0 disables task cleanup.
default: 259200
example: 259200
event_ttl_seconds:
type: integer
minimum: 0
description: Delete events older than this many seconds. 0 disables event cleanup.
default: 259200
example: 259200
Error:
type: object
required: [error, code]
properties:
error:
type: string
description: Human-readable error message
code:
type: string
description: Machine-readable error code
responses:
BadRequest:
description: Validation error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
example:
error: "task_name is required"
code: VALIDATION_ERROR
NotFound:
description: Resource not found
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
example:
error: "run not found"
code: NOT_FOUND
Conflict:
description: Conflict with current state
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
example:
error: "run already completed"
code: CONFLICT