Skip to content

Commit c3d9033

Browse files
committed
Fixed lint errors
1 parent b53c87c commit c3d9033

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

updatable_timer/starter.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ async def main(client: Optional[Client] = None):
2323
)
2424
logging.info(f"Workflow started: run_id={handle.result_run_id}")
2525
except exceptions.WorkflowAlreadyStartedError as e:
26-
logging.info(f"Workflow already running: workflow_id={e.workflow_id}, run_id={e.run_id}")
26+
logging.info(
27+
f"Workflow already running: workflow_id={e.workflow_id}, run_id={e.run_id}"
28+
)
2729

2830

2931
if __name__ == "__main__":

updatable_timer/updatable_timer_lib.py

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

66

77
class UpdatableTimer:
8-
98
def __init__(self, wake_up_time: datetime) -> None:
109
self.wake_up_time = wake_up_time
1110
self.wake_up_time_updated = False

updatable_timer/wake_up_time_updater.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import asyncio
22
import logging
3-
from datetime import timedelta, datetime
3+
from datetime import datetime, timedelta
44
from typing import Optional
55

66
from temporalio.client import Client
@@ -12,11 +12,12 @@ async def main(client: Optional[Client] = None):
1212
logging.basicConfig(level=logging.INFO)
1313

1414
client = client or await Client.connect("localhost:7233")
15-
handle = client.get_workflow_handle(
16-
workflow_id="updatable-timer-workflow"
17-
)
15+
handle = client.get_workflow_handle(workflow_id="updatable-timer-workflow")
1816
# signal workflow about the wake up time change
19-
await handle.signal(Workflow.update_wake_up_time, (datetime.now() + timedelta(seconds=10)).timestamp())
17+
await handle.signal(
18+
Workflow.update_wake_up_time,
19+
(datetime.now() + timedelta(seconds=10)).timestamp(),
20+
)
2021

2122
logging.info("Updated wake up time to 10 seconds from now")
2223

updatable_timer/worker.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ async def main():
1515

1616
client = await Client.connect("localhost:7233")
1717
async with Worker(
18-
client,
19-
task_queue=TASK_QUEUE,
20-
workflows=[Workflow],
18+
client,
19+
task_queue=TASK_QUEUE,
20+
workflows=[Workflow],
2121
):
2222
logging.info("Worker started, ctrl+c to exit")
2323
# Wait until interrupted

updatable_timer/workflow.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from datetime import datetime, timezone
2+
from typing import Optional
23

34
from temporalio import workflow
45

@@ -7,13 +8,14 @@
78

89
@workflow.defn
910
class Workflow:
10-
1111
def __init__(self):
12-
self.timer = None
12+
self.timer: Optional[UpdatableTimer] = None
1313

1414
@workflow.run
1515
async def run(self, wake_up_time: float):
16-
self.timer = UpdatableTimer(datetime.fromtimestamp(wake_up_time, tz=timezone.utc))
16+
self.timer = UpdatableTimer(
17+
datetime.fromtimestamp(wake_up_time, tz=timezone.utc)
18+
)
1719
await self.timer.sleep()
1820

1921
@workflow.signal
@@ -22,8 +24,12 @@ async def update_wake_up_time(self, wake_up_time: float):
2224
# This happens when a workflow task is executed after a signal is received
2325
# or when a workflow is started using the signal-with-start.
2426
await workflow.wait_condition(lambda: self.timer is not None)
25-
self.timer.update_wake_up_time(datetime.fromtimestamp(wake_up_time, tz=timezone.utc))
27+
assert self.timer is not None # for mypy
28+
self.timer.update_wake_up_time(
29+
datetime.fromtimestamp(wake_up_time, tz=timezone.utc)
30+
)
2631

2732
@workflow.query
2833
def get_wake_up_time(self):
34+
assert self.timer is not None # for mypy
2935
return self.timer.get_wake_up_time()

0 commit comments

Comments
 (0)