ActionModels::CleansUp deletes the action immediately after it's completed, which is nice for some things but for a lot of use cases I think a better design would be to delay cleanup by some number of minutes/hours/days. In particular, we can't use CleansUp with PerformsExport because if we do there's no way for the user to download the exported data. We do generally want these to be cleaned up, though, because old exports take up a lot of space in the db and/or attachment storage.
Possible design:
New mixin ActionModels::DelayedCleanUp
defines a delete_after attribute
defines a retain_for_interval class method with some reasonable default
defines a deletable scope that takes a datetime, defaulting to now, and finds all records where delete_after <= given_dt
before_create populate delete_after by adding retain_for_interval to created_at
Sidekiq worker that takes a class name and does class_name.constantize.deletable.destroy_all!
Maybe some kind of registration mechanism such that when the mixin is included it adds the including class to a registry of cleanup-able classes that the sidekiq worker uses
Queuing the sidekiq worker is the responsibility of the user because we can't assume they're using Sidekiq pro.
ActionModels::CleansUp
deletes the action immediately after it's completed, which is nice for some things but for a lot of use cases I think a better design would be to delay cleanup by some number of minutes/hours/days. In particular, we can't useCleansUp
withPerformsExport
because if we do there's no way for the user to download the exported data. We do generally want these to be cleaned up, though, because old exports take up a lot of space in the db and/or attachment storage.Possible design:
ActionModels::DelayedCleanUp
delete_after
attributeretain_for_interval
class method with some reasonable defaultdeletable
scope that takes a datetime, defaulting to now, and finds all records wheredelete_after <= given_dt
delete_after
by addingretain_for_interval
tocreated_at
class_name.constantize.deletable.destroy_all!
Queuing the sidekiq worker is the responsibility of the user because we can't assume they're using Sidekiq pro.