Skip to content

Commit 51c11e4

Browse files
committed
add url property to DescribeWorkflow and DescribeWorkflowDefinition
1 parent f1d9137 commit 51c11e4

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

jupyter_scheduler/extension.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,27 @@ class SchedulerApp(ExtensionApp):
4545
(r"scheduler/job_definitions/%s/jobs" % JOB_DEFINITION_ID_REGEX, JobFromDefinitionHandler),
4646
(r"scheduler/runtime_environments", RuntimeEnvironmentsHandler),
4747
(r"scheduler/config", ConfigHandler),
48-
(r"scheduler/worklows", WorkflowsHandler),
49-
(rf"scheduler/worklows/{WORKFLOW_ID_REGEX}", WorkflowsHandler),
48+
(r"scheduler/workflows", WorkflowsHandler),
49+
(rf"scheduler/workflows/{WORKFLOW_ID_REGEX}", WorkflowsHandler),
5050
(
51-
rf"scheduler/worklows/{WORKFLOW_ID_REGEX}/run",
51+
rf"scheduler/workflows/{WORKFLOW_ID_REGEX}/run",
5252
WorkflowsRunHandler,
5353
),
5454
(
55-
rf"scheduler/worklows/{WORKFLOW_ID_REGEX}/tasks",
55+
rf"scheduler/workflows/{WORKFLOW_ID_REGEX}/tasks",
5656
WorkflowsTasksHandler,
5757
),
58-
(r"scheduler/worklow_definitions", WorkflowDefinitionsHandler),
58+
(r"scheduler/workflow_definitions", WorkflowDefinitionsHandler),
5959
(
60-
rf"scheduler/worklow_definitions/{WORKFLOW_DEFINITION_ID_REGEX}",
60+
rf"scheduler/workflow_definitions/{WORKFLOW_DEFINITION_ID_REGEX}",
6161
WorkflowDefinitionsHandler,
6262
),
6363
(
64-
rf"scheduler/worklow_definitions/{WORKFLOW_DEFINITION_ID_REGEX}/deploy",
64+
rf"scheduler/workflow_definitions/{WORKFLOW_DEFINITION_ID_REGEX}/deploy",
6565
WorkflowDefinitionsDeploymentHandler,
6666
),
6767
(
68-
rf"scheduler/worklow_definitions/{WORKFLOW_DEFINITION_ID_REGEX}/tasks",
68+
rf"scheduler/workflow_definitions/{WORKFLOW_DEFINITION_ID_REGEX}/tasks",
6969
WorkflowDefinitionsTasksHandler,
7070
),
7171
]

jupyter_scheduler/workflows.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
UpdateJobDefinition,
2323
)
2424
from jupyter_scheduler.pydantic_v1 import BaseModel, ValidationError
25+
from urllib.parse import urlunparse
26+
from jupyter_server.utils import url_path_join
2527

2628

2729
class WorkflowsHandler(ExtensionHandlerMixin, JobHandlersMixin, APIHandler):
@@ -32,6 +34,13 @@ async def post(self):
3234
workflow_id = await ensure_async(
3335
self.scheduler.create_workflow(CreateWorkflow(**payload))
3436
)
37+
38+
protocol = self.request.protocol
39+
host = self.request.host
40+
base_url = self.base_url
41+
resource_path = url_path_join(base_url, "scheduler", "workflows", workflow_id)
42+
full_url = urlunparse((protocol, host, resource_path, "", "", ""))
43+
3544
except ValidationError as e:
3645
self.log.exception(e)
3746
raise HTTPError(500, str(e)) from e
@@ -48,7 +57,7 @@ async def post(self):
4857
self.log.exception(e)
4958
raise HTTPError(500, "Unexpected error occurred during creation of a workflow.") from e
5059
else:
51-
self.finish(json.dumps(dict(workflow_id=workflow_id)))
60+
self.finish(json.dumps(dict(workflow_id=workflow_id, url=full_url)))
5261

5362
@authenticated
5463
async def get(self, workflow_id: str = None):
@@ -192,6 +201,13 @@ async def post(self):
192201
workflow_definition_id = await ensure_async(
193202
self.scheduler.create_workflow_definition(CreateWorkflowDefinition(**payload))
194203
)
204+
protocol = self.request.protocol
205+
host = self.request.host
206+
base_url = self.base_url
207+
resource_path = url_path_join(
208+
base_url, "scheduler", "workflow_definitions", workflow_definition_id
209+
)
210+
full_url = urlunparse((protocol, host, resource_path, "", "", ""))
195211
except ValidationError as e:
196212
self.log.exception(e)
197213
raise HTTPError(500, str(e)) from e
@@ -210,7 +226,9 @@ async def post(self):
210226
500, "Unexpected error occurred during creation of a workflow definition."
211227
) from e
212228
else:
213-
self.finish(json.dumps(dict(workflow_definition_id=workflow_definition_id)))
229+
self.finish(
230+
json.dumps(dict(workflow_definition_id=workflow_definition_id, url=full_url))
231+
)
214232

215233
@authenticated
216234
async def get(self, workflow_definition_id: str = None):

0 commit comments

Comments
 (0)