|
1 |
| -from datetime import datetime |
| 1 | +import json |
| 2 | +import logging |
| 3 | +from typing import List, Any, Dict |
| 4 | + |
| 5 | +from dateutil.parser import parse as dt_parse |
| 6 | + |
| 7 | +from . import (RetryOptions) |
| 8 | +from .history import HistoryEvent, HistoryEventType |
| 9 | +from ..interfaces import IAction |
2 | 10 | from ..interfaces import ITaskMethods
|
3 |
| -from . import (Task, RetryOptions) |
| 11 | +from ..models.Task import Task |
| 12 | +from ..tasks import call_activity, task_all |
4 | 13 |
|
5 | 14 |
|
6 | 15 | class DurableOrchestrationContext:
|
7 | 16 |
|
8 | 17 | def __init__(self,
|
9 |
| - instanceId, |
10 |
| - isReplaying, |
11 |
| - parentInstanceId, |
12 |
| - callActivity, |
13 |
| - task_all, |
14 |
| - currentUtcDateTime): |
15 |
| - self.instanceId: str = instanceId |
16 |
| - self.isReplaying: bool = isReplaying |
17 |
| - self.parentInstanceId: str = parentInstanceId |
18 |
| - self.callActivity = callActivity |
19 |
| - self.task_all = task_all |
20 |
| - self.currentUtcDateTime = currentUtcDateTime |
21 |
| - |
22 |
| - # self.currentUtcDateTime: Date |
23 |
| - self.currentUtcDateTime: datetime |
| 18 | + context_string: str): |
| 19 | + context: Dict[str, Any] = json.loads(context_string) |
| 20 | + logging.warning(f"!!!Calling orchestrator handle {context}") |
| 21 | + self.histories: List[HistoryEvent] = context.get("history") |
| 22 | + self.instanceId = context.get("instanceId") |
| 23 | + self.isReplaying = context.get("isReplaying") |
| 24 | + self.parentInstanceId = context.get("parentInstanceId") |
| 25 | + self.callActivity = lambda n, i: call_activity( |
| 26 | + state=self.histories, |
| 27 | + name=n, |
| 28 | + input_=i) |
| 29 | + self.task_all = lambda t: task_all(state=self.histories, tasks=t) |
| 30 | + self.decision_started_event: HistoryEvent = list(filter( |
| 31 | + # HistoryEventType.OrchestratorStarted |
| 32 | + lambda e_: e_["EventType"] == HistoryEventType.OrchestratorStarted, |
| 33 | + self.histories))[0] |
| 34 | + self.currentUtcDateTime = dt_parse(self.decision_started_event["Timestamp"]) |
| 35 | + self.newGuidCounter = 0 |
| 36 | + self.actions: List[List[IAction]] = [] |
24 | 37 | self.Task: ITaskMethods
|
25 | 38 |
|
26 |
| - def callActivity(name: str, input=None) -> Task: |
| 39 | + def callActivity(name: str, input_=None) -> Task: |
27 | 40 | raise NotImplementedError("This is a placeholder.")
|
28 | 41 |
|
29 | 42 | def callActivityWithRetry(
|
|
0 commit comments