Hello Team,
I have a question about how to automatically renew the token before it expires so that the worker will not stop.
When I used the code snippet below, it threw an error.
Can you please suggest the correct solution?
[Referenced Link] temporalio.client.Client
I have tried the following approaches, but none of them worked.
1st way
async main():
client = await Client.connect(target_host=target_host, tls=True, rpc_metadata=get_token())
worker = Worker(client, task_queue="dummy", workflows=[Workflow], activities=[activity1, activity2])
await worker.run()
def get_token():
token = "logic to get the token"
return token
2nd way:
async main():
try:
client = await Client.connect(target_host=target_host, tls=True, rpc_metadata=get_token())
worker = Worker(client, task_queue="dummy", workflows=[Workflow], activities=[activity1, activity2])
await worker.run()
except Exception as err:
client.rpc_metadata=get_token()
worker = Worker(client, task_queue="dummy", workflows=[Workflow], activities=[activity1, activity2])
await worker.run()
def get_token():
token = "logic to get the token"
return token
3rd way: I think this will works but I am not sure every time is it create new worker?
async main():
while True:
try:
client = await Client.connect(target_host=target_host, tls=True, rpc_metadata=get_token())
worker = Worker(client, task_queue="dummy", workflows=[Workflow], activities=[activity1, activity2])
await worker.run()
except Exception as err:
print(f"Exception {err}"")
continue
def get_token():
token = "logic to get the token"
return token