Answer the question
In order to leave comments, you need to log in
How to execute Ruby method to check DB data every second?
Users save information to the database and choose an expiration date in seconds (maybe 10 seconds, maybe 1800). After this time from the moment of creation, it is necessary to run a certain trigger. Cron tasks can be run at least once per minute.
Solution used
loop do
Foo.check
sleep 1
end
Answer the question
In order to leave comments, you need to log in
You can use the Sidekiq gem - an analogue of a cron for Rails.
When the user adds an entry - add the task to Sidekiq, with a delay that the user has specified.
Read more here - Sidekiq
Task queue (delayed job, sidekiq, resque) + scheduler ( https://github.com/tomykaira/clockwork )
Run in cron, process multiple entries in each run. The main thing is not to forget about locks, so that it works well if suddenly two processes are running at once - both in terms of speed and in terms of data integrity. I usually use DB level locks (MySQL GET_LOCK)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question