Skip to content

Commit b53c87c

Browse files
committed
Converted updatable_timer to a module
1 parent b0d9238 commit b53c87c

File tree

6 files changed

+13
-9
lines changed

6 files changed

+13
-9
lines changed

updatable_timer/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TASK_QUEUE = "updatable-timer"

updatable_timer/starter.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
from temporalio import exceptions
77
from temporalio.client import Client
88

9-
from workflow import Workflow
9+
from updatable_timer import TASK_QUEUE
10+
from updatable_timer.workflow import Workflow
1011

1112

1213
async def main(client: Optional[Client] = None):
@@ -18,7 +19,7 @@ async def main(client: Optional[Client] = None):
1819
Workflow.run,
1920
(datetime.now() + timedelta(days=1)).timestamp(),
2021
id=f"updatable-timer-workflow",
21-
task_queue="updatable-timer",
22+
task_queue=TASK_QUEUE,
2223
)
2324
logging.info(f"Workflow started: run_id={handle.result_run_id}")
2425
except exceptions.WorkflowAlreadyStartedError as e:

updatable_timer/wake_up_time_updater.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from temporalio.client import Client
77

8-
from workflow import Workflow
8+
from updatable_timer.workflow import Workflow
99

1010

1111
async def main(client: Optional[Client] = None):

updatable_timer/worker.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
from temporalio.client import Client
55
from temporalio.worker import Worker
6-
from workflow import Workflow
6+
7+
from updatable_timer import TASK_QUEUE
8+
from updatable_timer.workflow import Workflow
79

810
interrupt_event = asyncio.Event()
911

@@ -14,7 +16,7 @@ async def main():
1416
client = await Client.connect("localhost:7233")
1517
async with Worker(
1618
client,
17-
task_queue="updatable-timer",
19+
task_queue=TASK_QUEUE,
1820
workflows=[Workflow],
1921
):
2022
logging.info("Worker started, ctrl+c to exit")

updatable_timer/workflow.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from temporalio import workflow
44

5-
from updatable_timer import UpdatableTimer
5+
from updatable_timer.updatable_timer_lib import UpdatableTimer
66

77

88
@workflow.defn
@@ -18,9 +18,9 @@ async def run(self, wake_up_time: float):
1818

1919
@workflow.signal
2020
async def update_wake_up_time(self, wake_up_time: float):
21-
# Deals with situation when signal method is called before run method.
22-
# This happens when workflow task is executed after the signal is received
23-
# or when workflow is started using signal with start.
21+
# Deals with situation when the signal method is called before the run method.
22+
# This happens when a workflow task is executed after a signal is received
23+
# or when a workflow is started using the signal-with-start.
2424
await workflow.wait_condition(lambda: self.timer is not None)
2525
self.timer.update_wake_up_time(datetime.fromtimestamp(wake_up_time, tz=timezone.utc))
2626

0 commit comments

Comments
 (0)