How To: Clear expired client access tokens with a database job
Currently, the API handles clearing expired client access tokens with a background task that runs on a configurable interval. This approach was chosen for "out of the box" experience to ensure a seamless experience from the get-go, owing to its simplicity and adaptability across various deployment environments. However, in this default implementation, when multiple instances of the API are operational, each instance triggers the background task, leading to redundant executions of the cleanup process. To prevent this, one option is to disable the 'DeleteExpiredTokens' background task on all instances of the API server except for one. Alternatively, you could entirely switch to an external process. A solution of this nature is detailed in this article. It demonstrates how to configure a scheduled job running on the database server that hosts the Ed-Fi-Admin database.
Implementation Steps
- Disable API background task
- Verify that the database server job agent is enabled and running
- Create scheduled job which consists of:
- Job - to encapsulate all job steps
- Job Step - to execute the command(s)
- Schedule - to schedule when the job and all of its steps will be executed
Disable API background task
"ScheduledJobs": [ { "Name": "DeleteExpiredTokens", "IsEnabled": false, "CronExpression": "0 0/30 * 1/1 * ? *" } ]
Create Scheduled Job
Modify and execute the SQL Server or PostgreSQL script below in order to create the scheduled job within your database server.