Reputation: 3520
I am trying to create the functionality in my app where a given entry in the database is set to delete at a certain time. I am new to rails an I am unsure how I can achieve this.
For example, once the expired time of an entry has been passed I want it to be deleted automatically. Any hints or ideas how this can be achieved? Thanks again.
Upvotes: 1
Views: 251
Reputation: 6862
Background job is what will solve your problem. Resque
and Sidekiq
are two awesome options on background job. You can keep scheduler that runs in specific interval to check if entry has expired and if yes, delete the entry. Here is the railcasts on resque and [this one]. Whenever is also an option but the other two mentioned above are still better.
Upvotes: 2
Reputation: 230296
You can run a rake task periodically (like every hour or every night). This job will check posts and delete expired ones.
You can schedule rake tasks using whenever
gem, for example.
every 3.hours do
rake "jobs:clear_stale"
end
Upvotes: 2