I have one TSQ in my program to keep an OKTA token which expires after every 8 hour.
The TSQ record will have token value and Expiration timestamp.
On Expiry of the token, the program calls the OKTA WEB APIs and get a new token and updates the TSQ with new token.
This program can be called many times in a second. How I can prevent multiple Tran/tasks updating the tsq when the token expires?
Currently I am exploring the option of ENQ and DEQ. Can someone advice me that will be a better option ?
Any different thoughts other than TSQ also fine
Thinking to try the below code
working-storage. 01 ws-tsq-name x(16)
PROCEDURE DIVISION.
a100-token-expiry section.
read the token tsq
if token expired or tsq doesnt exist
perform a200-get-token.
end-if
a100-exit. exit.
a200-get-token section.
exec cics enq
resource (ws-tsq-name)
length(length of ws-tsq-name)
nosuspend
resp(ws-resp1)
resp2 (ws-resp2)
end-exec
if ws-resp2 = dfhresp(enqbusy)
set ws-enqbusy to true
end-if
if ws-enqbusy
link to okta token api program and get the token
pass the token to caller
else
link to okta token api program and get the token
create/update the tsq
pass the token to caller
exec cics deq
resource (ws-tsq-name)
length(length of ws-tsq-name)
resp(ws-resp1)
resp2 (ws-resp2)
end-exec
end-if