Skip to content

Commit 1433cb9

Browse files
feat: pull based job agents (#1157)
1 parent 4373ced commit 1433cb9

31 files changed

Lines changed: 8199 additions & 18 deletions

File tree

‎apps/api/openapi/openapi.json‎

Lines changed: 207 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,8 @@
13921392
"invalidJobAgent",
13931393
"invalidIntegration",
13941394
"externalRunNotFound",
1395-
"successful"
1395+
"successful",
1396+
"queued"
13961397
],
13971398
"type": "string"
13981399
},
@@ -6312,6 +6313,211 @@
63126313
"summary": "Upsert a job agent"
63136314
}
63146315
},
6316+
"/v1/workspaces/{workspaceId}/job-agents/{jobAgentId}/jobs": {
6317+
"get": {
6318+
"description": "Returns the jobs assigned to a job agent, optionally filtered by status.",
6319+
"operationId": "listJobAgentJobs",
6320+
"parameters": [
6321+
{
6322+
"description": "ID of the workspace",
6323+
"in": "path",
6324+
"name": "workspaceId",
6325+
"required": true,
6326+
"schema": {
6327+
"type": "string"
6328+
}
6329+
},
6330+
{
6331+
"description": "ID of the job agent",
6332+
"in": "path",
6333+
"name": "jobAgentId",
6334+
"required": true,
6335+
"schema": {
6336+
"type": "string"
6337+
}
6338+
},
6339+
{
6340+
"description": "Filter jobs by status",
6341+
"in": "query",
6342+
"name": "status",
6343+
"required": false,
6344+
"schema": {
6345+
"$ref": "#/components/schemas/JobStatus"
6346+
}
6347+
},
6348+
{
6349+
"description": "Include the dispatch context on each job. It can be large, so it is omitted by default.",
6350+
"in": "query",
6351+
"name": "includeDispatchContext",
6352+
"required": false,
6353+
"schema": {
6354+
"default": false,
6355+
"type": "boolean"
6356+
}
6357+
},
6358+
{
6359+
"description": "Maximum number of items to return",
6360+
"in": "query",
6361+
"name": "limit",
6362+
"required": false,
6363+
"schema": {
6364+
"default": 50,
6365+
"maximum": 1000,
6366+
"minimum": 1,
6367+
"type": "integer"
6368+
}
6369+
},
6370+
{
6371+
"description": "Number of items to skip",
6372+
"in": "query",
6373+
"name": "offset",
6374+
"required": false,
6375+
"schema": {
6376+
"default": 0,
6377+
"minimum": 0,
6378+
"type": "integer"
6379+
}
6380+
}
6381+
],
6382+
"responses": {
6383+
"200": {
6384+
"content": {
6385+
"application/json": {
6386+
"schema": {
6387+
"properties": {
6388+
"items": {
6389+
"items": {
6390+
"$ref": "#/components/schemas/Job"
6391+
},
6392+
"type": "array"
6393+
},
6394+
"limit": {
6395+
"description": "Maximum number of items returned",
6396+
"type": "integer"
6397+
},
6398+
"offset": {
6399+
"description": "Number of items skipped",
6400+
"type": "integer"
6401+
},
6402+
"total": {
6403+
"description": "Total number of items available",
6404+
"type": "integer"
6405+
}
6406+
},
6407+
"required": [
6408+
"items",
6409+
"total",
6410+
"limit",
6411+
"offset"
6412+
],
6413+
"type": "object"
6414+
}
6415+
}
6416+
},
6417+
"description": "Paginated list of items"
6418+
},
6419+
"400": {
6420+
"content": {
6421+
"application/json": {
6422+
"schema": {
6423+
"$ref": "#/components/schemas/ErrorResponse"
6424+
}
6425+
}
6426+
},
6427+
"description": "Invalid request"
6428+
},
6429+
"404": {
6430+
"content": {
6431+
"application/json": {
6432+
"schema": {
6433+
"$ref": "#/components/schemas/ErrorResponse"
6434+
}
6435+
}
6436+
},
6437+
"description": "Resource not found"
6438+
}
6439+
},
6440+
"summary": "List jobs for a job agent"
6441+
}
6442+
},
6443+
"/v1/workspaces/{workspaceId}/job-agents/{jobAgentId}/jobs/{jobId}/claim": {
6444+
"post": {
6445+
"description": "Atomically claims a queued job for the job agent, transitioning it to in progress. Returns 409 if the job is no longer available to claim.",
6446+
"operationId": "claimJob",
6447+
"parameters": [
6448+
{
6449+
"description": "ID of the workspace",
6450+
"in": "path",
6451+
"name": "workspaceId",
6452+
"required": true,
6453+
"schema": {
6454+
"type": "string"
6455+
}
6456+
},
6457+
{
6458+
"description": "ID of the job agent",
6459+
"in": "path",
6460+
"name": "jobAgentId",
6461+
"required": true,
6462+
"schema": {
6463+
"type": "string"
6464+
}
6465+
},
6466+
{
6467+
"description": "ID of the job",
6468+
"in": "path",
6469+
"name": "jobId",
6470+
"required": true,
6471+
"schema": {
6472+
"type": "string"
6473+
}
6474+
}
6475+
],
6476+
"responses": {
6477+
"200": {
6478+
"content": {
6479+
"application/json": {
6480+
"schema": {
6481+
"$ref": "#/components/schemas/Job"
6482+
}
6483+
}
6484+
},
6485+
"description": "Job claimed"
6486+
},
6487+
"400": {
6488+
"content": {
6489+
"application/json": {
6490+
"schema": {
6491+
"$ref": "#/components/schemas/ErrorResponse"
6492+
}
6493+
}
6494+
},
6495+
"description": "Invalid request"
6496+
},
6497+
"404": {
6498+
"content": {
6499+
"application/json": {
6500+
"schema": {
6501+
"$ref": "#/components/schemas/ErrorResponse"
6502+
}
6503+
}
6504+
},
6505+
"description": "Resource not found"
6506+
},
6507+
"409": {
6508+
"content": {
6509+
"application/json": {
6510+
"schema": {
6511+
"$ref": "#/components/schemas/ErrorResponse"
6512+
}
6513+
}
6514+
},
6515+
"description": "Job is not available to claim"
6516+
}
6517+
},
6518+
"summary": "Claim a job"
6519+
}
6520+
},
63156521
"/v1/workspaces/{workspaceId}/jobs": {
63166522
"get": {
63176523
"description": "Returns a list of jobs.",

‎apps/api/openapi/paths/job-agents.jsonnet‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,50 @@ local openapi = import '../lib/openapi.libsonnet';
5656
+ openapi.badRequestResponse(),
5757
},
5858
},
59+
'/v1/workspaces/{workspaceId}/job-agents/{jobAgentId}/jobs': {
60+
get: {
61+
summary: 'List jobs for a job agent',
62+
operationId: 'listJobAgentJobs',
63+
description: 'Returns the jobs assigned to a job agent, optionally filtered by status.',
64+
parameters: [
65+
openapi.workspaceIdParam(),
66+
openapi.jobAgentIdParam(),
67+
{
68+
name: 'status',
69+
'in': 'query',
70+
required: false,
71+
description: 'Filter jobs by status',
72+
schema: openapi.schemaRef('JobStatus'),
73+
},
74+
{
75+
name: 'includeDispatchContext',
76+
'in': 'query',
77+
required: false,
78+
description: 'Include the dispatch context on each job. It can be large, so it is omitted by default.',
79+
schema: { type: 'boolean', default: false },
80+
},
81+
openapi.limitParam(),
82+
openapi.offsetParam(),
83+
],
84+
responses: openapi.paginatedResponse(openapi.schemaRef('Job'))
85+
+ openapi.notFoundResponse()
86+
+ openapi.badRequestResponse(),
87+
},
88+
},
89+
'/v1/workspaces/{workspaceId}/job-agents/{jobAgentId}/jobs/{jobId}/claim': {
90+
post: {
91+
summary: 'Claim a job',
92+
operationId: 'claimJob',
93+
description: 'Atomically claims a queued job for the job agent, transitioning it to in progress. Returns 409 if the job is no longer available to claim.',
94+
parameters: [
95+
openapi.workspaceIdParam(),
96+
openapi.jobAgentIdParam(),
97+
openapi.jobIdParam(),
98+
],
99+
responses: openapi.okResponse(openapi.schemaRef('Job'), 'Job claimed')
100+
+ openapi.conflictResponse('Job is not available to claim')
101+
+ openapi.notFoundResponse()
102+
+ openapi.badRequestResponse(),
103+
},
104+
},
59105
}

‎apps/api/openapi/schemas/jobs.jsonnet‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ local JobPropertyKeys = std.objectFields(Job.properties);
5656
'invalidIntegration',
5757
'externalRunNotFound',
5858
'successful',
59+
'queued',
5960
],
6061
},
6162

0 commit comments

Comments
 (0)