#Soft delete after delay (expiration date)
1 messages · Page 1 of 1 (latest)
You can write a job that run on scheduled basis. It goes through entities and soft delete those matching the criteria.
See: https://docs.vapor.codes/advanced/queues/#queues
Vapors documentation (web framework for Swift).
Sorry, maybe I didn't explain well enough.
For instance, I am periodically generating public/private keys on a scheduled job. When I create the key, I know when I want it to expire, and want to set the soft-delete to that exact date. So that the public keys won't be returned by queries past this date - without having to run another job to delete them.
Another use case is to immediately expire a session token when refreshing it with a newer one, but actually allow a few more seconds on the old one, so that concurrent requests sent with the old token do not get rejected because they reach after the refresh.
So in both cases, either at creation time, or after something happened, I know the exact future date I want the soft delete to be effective. But the delete() call do not allow to manually specify the date, and I wonder if there is a cleaner way than manually modifying the soft deletion myself.
Well, I would say my reply still fits those use cases. There is no mechanism to trigger a soft deletion at specified time. Scheduled job is really the easiest way to achieve it. The job can run e.g. every minute or even more often. It simply query all records which are not deleted and their expiration date is in the past.
I didn’t get the point of the second use case (about session expiration delay). If it’s expired, then it’s expired and it’s up to refresh token mechanism to get a new token, isn’t it?
soft delete is a Date, not a boolean. If I am not mistaken, it is for the exact purpose of checking Date.now against the soft delete date on all queries
Say, I'm sending a bunch of requests to my API on mobile network with the current token. One of those requests is a token refresh request. Depending on the order they arrive, the refresh token request may cause other requests to fail. This is not desired
Vapors documentation (web framework for Swift).
You can manually set an on delete timestamp to a date in the future. This can be used as an expiration date.