1 #######################################################################################
2 # Copyright ETSI Contributors and Others.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #######################################################################################
21 from temporalio
.client
import Client
24 class WFTemporal(object):
28 def __init__(self
, logger_name
="temporal.client"):
29 self
.logger
= logging
.getLogger(logger_name
)
31 async def execute_workflow(
32 self
, task_queue
: str, workflow_name
: str, workflow_data
: any
, id: str = None
34 handle
= await self
.start_workflow(
35 task_queue
=task_queue
,
36 workflow_name
=workflow_name
,
37 workflow_data
=workflow_data
,
40 result
= await handle
.result()
41 self
.logger
.info(f
"Completed workflow {workflow_name}, id {id}")
44 async def start_workflow(
45 self
, task_queue
: str, workflow_name
: str, workflow_data
: any
, id: str = None
47 if WFTemporal
._client
is None:
49 f
"No cached client found, connecting to {WFTemporal.temporal_api}"
51 WFTemporal
._client
= await Client
.connect(WFTemporal
.temporal_api
)
54 id = str(uuid
.uuid4())
55 self
.logger
.info(f
"Starting workflow {workflow_name}, id {id}")
56 handle
= await WFTemporal
._client
.start_workflow(
57 workflow
=workflow_name
, arg
=workflow_data
, id=id, task_queue
=task_queue