-
Notifications
You must be signed in to change notification settings - Fork 56
/
create_schedule.py
64 lines (56 loc) · 1.83 KB
/
create_schedule.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import asyncio
import traceback
from datetime import datetime, timedelta
from temporalio.client import (
Client,
Schedule,
ScheduleActionStartWorkflow,
ScheduleIntervalSpec,
ScheduleSpec,
WorkflowFailureError,
)
from cloud_export_to_parquet.workflows import (
ProtoToParquet,
ProtoToParquetWorkflowInput,
)
async def main() -> None:
"""Main function to run temporal workflow."""
# Create client connected to server at the given address
client = await Client.connect("localhost:7233")
# TODO: update s3_bucket and namespace to the actual usecase
wf_input = ProtoToParquetWorkflowInput(
num_delay_hour=2,
export_s3_bucket="test-input-bucket",
namespace="test.namespace",
output_s3_bucket="test-output-bucket",
)
# Run the workflow
# try:
# await client.start_workflow(
# ProtoToParquet.run,
# wf_input,
# id = f"proto-to-parquet-{datetime.now()}",
# task_queue="DATA_TRANSFORMATION_TASK_QUEUE",
# )
# except WorkflowFailureError:
# print("Got exception: ", traceback.format_exc())
# Create the schedule
try:
await client.create_schedule(
"hourly-proto-to-parquet-wf-schedule",
Schedule(
action=ScheduleActionStartWorkflow(
ProtoToParquet.run,
wf_input,
id=f"proto-to-parquet-{datetime.now()}",
task_queue="DATA_TRANSFORMATION_TASK_QUEUE",
),
spec=ScheduleSpec(
intervals=[ScheduleIntervalSpec(every=timedelta(hours=1))]
),
),
)
except WorkflowFailureError:
print("Got exception: ", traceback.format_exc())
if __name__ == "__main__":
asyncio.run(main())