in rails 3 app, need create objects persistent specified time. example, created activerecord object (of model) need around 12 hours. activerecord object needs automatically destroyed database after 12 hours. there no need deletion happen through controller, happen directly on database. best way achieve this? there might thousands of such objects getting created , destroyed @ timer , each needs destroyed @ specified time.
i looked around , found gems - whenever & delayed job. whenever more of wrapper on cron , hence not suitable considering number of activerecord objects managed. yet investigate 'delayed job' uses background process, wanted feedback on available options.
thanks in advance.
why don't run cron/whenever job every few minutes queries database objects created_at > 12.hours.ago? manage delete objects query instead of going 1 one.
every 5.minutes model.where(:created_at > 12.hours.ago).delete_all end if need more precise, can imagine using redis keys objects , setting time expiration on keys @ 12 hours, though need figure out how connect redis.
in case, needs observing database happen, or have expiring keys.
Comments
Post a Comment