I have a model Item
which stores user items. This model has a field endDate
at which the instances have to be marked for deletion by setting expired
field to true. Is there some way I can do this in loopback/express automatically? I am using postgresql
as database.
I can think of following 2 ways but I don't think they are the best solutions for this problem:
1) Using setTimeout
I can call a function which would mark the items for deletion. This solution is not at all scalable as it is not stateless
and if there are multiple instances of node
running, this would cause issues.
2) Use redis
database and for each item create a key in redis
with expire time. redis
will automatically call a function when the timer expires and I can delete the item then. This I think is scalable as this is stateless
.
Is there a more efficient solution to this?
Edit
I want to notify the user also as soon as the item expires. So, I would need a function call to happen as soon as expiration happens. So setting expireAt key and running a cleanup utility at intervals, will not be of much help here.