Timer kind in the application

0
Hi,   I have token generated through a rest services , after 8 hours the token will expire and I have to create an token. I need a mechanism which triggeres after 8 hrs and set an boolean which tells me whether the token is expired or not. I know this can he accomplised by Scheduled Event. But in Scheduling event I cant give the save date of the token i can only give a standard date. Is there any other trigger kind mechainsm ?    
asked
2 answers
0

Swathi,

I am assuming you store the token in an entity.  If so, add an attribute to the entity to store the datetime stamp that the token was last updated.  Then in your scheduled event, you can retrieve the record from this entity with your token, check the last update datetime and see if it was more than 8 hours ago.  If it was, you can generate a new token and store it in the entity.

Alternatively, if you use the token primarily in microflows, you could check the token age at the beginning of each microflow and generate a new one if required.  Depending on the number of activities that use the token, this could require fewer resources than the first approach I describe above.  This method also has the advantage of not having to deal with an expired token, i.e. if it is expired, you just generate a new one.

Hope that helps,

Mike

answered
0

I assume the token is saved in an entity. Make sure you save the created date of that entity (tick the box). This way you can set a scheduled event (lets say every 15 minutes) that uses the hoursBetween function call (https://docs.mendix.com/refguide6/Between+date+function+calls)

Create a variabe date and fill it with the current datetime. Iterate over each token (or use an xpath to retrieve all older then 8 hours tokens) and check if the difference between de creation date and the current date is bigger then 8 hours. If so do the stuff you want to do (create a new token or remove the token).

Hope this helps,

Ronald

 

 

answered