|
46 | 46 | create_output_directory,
|
47 | 47 | create_output_filename,
|
48 | 48 | )
|
49 |
| -from jupyter_scheduler.workflows import CreateWorkflow, DescribeWorkflow |
| 49 | +from jupyter_scheduler.workflows import CreateWorkflow, DescribeWorkflow, UpdateWorkflow |
50 | 50 |
|
51 | 51 |
|
52 | 52 | class BaseScheduler(LoggingConfigurable):
|
@@ -124,6 +124,10 @@ def get_workflow(self, workflow_id: str) -> DescribeWorkflow:
|
124 | 124 | """Returns workflow record for a single workflow."""
|
125 | 125 | raise NotImplementedError("must be implemented by subclass")
|
126 | 126 |
|
| 127 | + def create_workflow_task(self, workflow_id: str, model: CreateJob) -> str: |
| 128 | + """Adds a task to a workflow.""" |
| 129 | + raise NotImplementedError("must be implemented by subclass") |
| 130 | + |
127 | 131 | def update_job(self, job_id: str, model: UpdateJob):
|
128 | 132 | """Updates job metadata in the persistence store,
|
129 | 133 | for example name, status etc. In case of status
|
@@ -565,6 +569,14 @@ def get_workflow(self, workflow_id: str) -> DescribeWorkflow:
|
565 | 569 | model = DescribeWorkflow.from_orm(workflow_record)
|
566 | 570 | return model
|
567 | 571 |
|
| 572 | + def create_workflow_task(self, workflow_id: str, model: CreateJob) -> str: |
| 573 | + job_id = self.scheduler.create_job(model, run=False) |
| 574 | + workflow: DescribeWorkflow = self.scheduler.get_workflow(workflow_id) |
| 575 | + updated_tasks = (workflow.tasks or [])[:] |
| 576 | + updated_tasks.append(job_id) |
| 577 | + self.scheduler.update_workflow(workflow_id, UpdateWorkflow(depends_on=updated_tasks)) |
| 578 | + return job_id |
| 579 | + |
568 | 580 | def update_job(self, job_id: str, model: UpdateJob):
|
569 | 581 | with self.db_session() as session:
|
570 | 582 | session.query(Job).filter(Job.job_id == job_id).update(model.dict(exclude_none=True))
|
|
0 commit comments