|
19 | 19 | from jupyter_scheduler.orm import Job, Workflow, create_session |
20 | 20 | from jupyter_scheduler.parameterize import add_parameters |
21 | 21 | from jupyter_scheduler.utils import get_utc_timestamp |
22 | | -from jupyter_scheduler.workflows import DescribeWorkflow |
| 22 | +from jupyter_scheduler.workflows import DescribeTask, DescribeWorkflow |
23 | 23 |
|
24 | 24 |
|
25 | 25 | class ExecutionManager(ABC): |
@@ -188,26 +188,40 @@ class DefaultExecutionManager(ExecutionManager): |
188 | 188 | """Default execution manager that executes notebooks""" |
189 | 189 |
|
190 | 190 | @task(task_run_name="{task_id}") |
191 | | - def execute_task(task_id: str): |
| 191 | + def execute_task(self, task_id: str): |
192 | 192 | print(f"Task {task_id} executed") |
193 | 193 | return task_id |
194 | 194 |
|
195 | | - @flow(task_runner=DaskTaskRunner()) |
| 195 | + @task |
| 196 | + def get_task_data(self, task_ids: List[str] = []): |
| 197 | + # TODO: get orm objects from Task table of the db, create DescribeTask for each |
| 198 | + tasks_data_obj = [ |
| 199 | + {"id": "task0", "dependsOn": ["task3"]}, |
| 200 | + {"id": "task4", "dependsOn": ["task0", "task1", "task2", "task3"]}, |
| 201 | + {"id": "task1", "dependsOn": []}, |
| 202 | + {"id": "task2", "dependsOn": ["task1"]}, |
| 203 | + {"id": "task3", "dependsOn": ["task1", "task2"]}, |
| 204 | + ] |
| 205 | + |
| 206 | + return tasks_data_obj |
| 207 | + |
| 208 | + @flow() |
196 | 209 | def execute_workflow(self): |
197 | | - workflow: DescribeWorkflow = self.model |
198 | | - tasks = {task["id"]: task for task in workflow.tasks} |
| 210 | + |
| 211 | + tasks_info = self.get_task_data() |
| 212 | + tasks = {task["id"]: task for task in tasks_info} |
199 | 213 |
|
200 | 214 | # create Prefect tasks, use caching to ensure Prefect tasks are created before wait_for is called on them |
201 | 215 | @lru_cache(maxsize=None) |
202 | | - def make_task(task_id, execute_task): |
| 216 | + def make_task(task_id): |
203 | 217 | deps = tasks[task_id]["dependsOn"] |
204 | | - return execute_task.submit( |
205 | | - task_id, wait_for=[make_task(dep_id, execute_task) for dep_id in deps] |
| 218 | + return self.execute_task.submit( |
| 219 | + task_id, wait_for=[make_task(dep_id) for dep_id in deps] |
206 | 220 | ) |
207 | 221 |
|
208 | | - final_tasks = [make_task(task_id, self.execute_task) for task_id in tasks] |
| 222 | + final_tasks = [make_task(task_id) for task_id in tasks] |
209 | 223 | for future in as_completed(final_tasks): |
210 | | - print(future.result()) |
| 224 | + future.result() |
211 | 225 |
|
212 | 226 | def execute(self): |
213 | 227 | job = self.model |
|
0 commit comments