Hi Team ,
In my script my token is getting expired with 5 min and my worker script is getting exited
How to refresh the token before it expires without exiting the worker
below is my code
def fetch_oauth_token(ca_cert_path):
auth_server_url = os.getenv("AUTH_SERVER_URL")
payload = {
"grant_type": "client_credentials",
"client_id": os.getenv("ZEEBE_CLIENT_ID"),
"client_secret": os.getenv("ZEEBE_CLIENT_SECRET"),
"audience": os.getenv("ZEEBE_AUDIENCE")
}
response = requests.post(auth_server_url, data=payload, verify=ca_cert_path)
response.raise_for_status()
token= response.json()["access_token"]
print(token)
return response.json()["access_token"]
async def main():
ca_cert_name = os.getenv("CA_CERT_NAME")
jwt_cert_name = os.getenv("JWT_CERT_NAME")
# Load the CA and JWT certificates
certs_dir = os.path.join("Certs")
ca_cert_path = os.path.join(certs_dir, ca_cert_name)
jwt_cert_path = os.path.join(certs_dir, jwt_cert_name)
with open(ca_cert_path, "rb") as pem_file:
ca_cert = pem_file.read()
jwt_token = fetch_oauth_token(jwt_cert_path)
ssl_credentials = grpc.ssl_channel_credentials(root_certificates=ca_cert)
token_credentials = grpc.access_token_call_credentials(jwt_token)
composite_credentials = grpc.composite_channel_credentials(ssl_credentials, token_credentials)
channel = create_secure_channel(hostname=ZEEBE_HOSTNAME, port=ZEEBE_PORT, channel_credentials=composite_credentials)
print(channel.get_state())
worker = ZeebeWorker(channel)
worker.task(task_type="mypython")(extract_text_handler)
print("Job workers open to receive jobs")
await worker.work()