Skip to content

Commit b33191c

Browse files
committed
add GET workflow/{id}
1 parent c64a53b commit b33191c

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

jupyter_scheduler/extension.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class SchedulerApp(ExtensionApp):
3838
(r"scheduler/runtime_environments", RuntimeEnvironmentsHandler),
3939
(r"scheduler/config", ConfigHandler),
4040
(r"scheduler/worklows", WorkflowHandler),
41+
(r"scheduler/worklows/{}".format(WORKFLOW_ID_REGEX), WorkflowHandler),
4142
(
4243
fr"scheduler/worklows/{WORKFLOW_ID_REGEX}/run",
4344
WorkflowRunHandler,

jupyter_scheduler/models.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ def __str__(self) -> str:
4242

4343

4444
class Status(str, Enum):
45-
DRAFT = "DRAFT"
4645
CREATED = "CREATED"
4746
QUEUED = "QUEUED"
4847
IN_PROGRESS = "IN_PROGRESS"

jupyter_scheduler/orm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class Workflow(Base):
114114
__table_args__ = {"extend_existing": True}
115115
workflow_id = Column(String(36), primary_key=True, default=generate_uuid)
116116
tasks = Column(JsonType(1024))
117-
status = Column(String(64), default=Status.DRAFT)
117+
status = Column(String(64), default=Status.CREATED)
118118
# All new columns added to this table must be nullable to ensure compatibility during database migrations.
119119
# Any default values specified for new columns will be ignored during the migration process.
120120

jupyter_scheduler/scheduler.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
create_output_directory,
4747
create_output_filename,
4848
)
49-
from jupyter_scheduler.workflows import CreateWorkflow
49+
from jupyter_scheduler.workflows import CreateWorkflow, DescribeWorkflow
5050

5151

5252
class BaseScheduler(LoggingConfigurable):
@@ -113,7 +113,15 @@ def create_job(self, model: CreateJob) -> str:
113113
raise NotImplementedError("must be implemented by subclass")
114114

115115
def create_workflow(self, model: CreateWorkflow) -> str:
116-
"""Creates a new workflow record, may trigger execution of the workflow."""
116+
"""Creates a new workflow record."""
117+
raise NotImplementedError("must be implemented by subclass")
118+
119+
def run_workflow(self, workflow_id: str) -> str:
120+
"""Triggers execution of the workflow."""
121+
raise NotImplementedError("must be implemented by subclass")
122+
123+
def get_workflow(self, workflow_id: str) -> DescribeWorkflow:
124+
"""Returns workflow record for a single workflow."""
117125
raise NotImplementedError("must be implemented by subclass")
118126

119127
def update_job(self, job_id: str, model: UpdateJob):
@@ -546,6 +554,14 @@ def run_workflow(self, workflow_id: str) -> str:
546554
execution_manager.process_workflow()
547555
return workflow_id
548556

557+
def get_workflow(self, workflow_id: str) -> DescribeWorkflow:
558+
with self.db_session() as session:
559+
workflow_record = (
560+
session.query(Workflow).filter(Workflow.workflow_id == workflow_id).one()
561+
)
562+
model = DescribeWorkflow.from_orm(workflow_record)
563+
return model
564+
549565
def update_job(self, job_id: str, model: UpdateJob):
550566
with self.db_session() as session:
551567
session.query(Job).filter(Job.job_id == job_id).update(model.dict(exclude_none=True))

jupyter_scheduler/workflows.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@ async def post(self):
4444
else:
4545
self.finish(json.dumps(dict(workflow_id=workflow_id)))
4646

47+
@authenticated
48+
async def get(self, workflow_id: str = None):
49+
if not workflow_id:
50+
raise HTTPError(400, "Missing workflow_id in the request URL.")
51+
try:
52+
workflow = await ensure_async(self.scheduler.get_workflow(workflow_id))
53+
except SchedulerError as e:
54+
self.log.exception(e)
55+
raise HTTPError(500, str(e)) from e
56+
except Exception as e:
57+
self.log.exception(e)
58+
raise HTTPError(500, "Unexpected error occurred while getting workflow details.") from e
59+
else:
60+
self.finish(workflow.json())
61+
4762

4863
class WorkflowRunHandler(ExtensionHandlerMixin, JobHandlersMixin, APIHandler):
4964
@authenticated

0 commit comments

Comments
 (0)