for regularly scheduled jobs, I use a mixture of cron (to create a delayed
job), and the delayed_job itself

the crontab instance is very light, just a small (non-rails) rb script to
insert the delayed_job in the delayed_jobs table

then the delayed_job instance will pickup the job and run it

in your instance, I would create a class method on the Test model -
something like

def self.remove_old_unpublished
  delete_all(["created_at < ? and state in('unpublished')", 24.hours.ago])
end

cron entry like this:
05 1 * * * cd /path/to/current &&
RAILS_ENV=production
/path/to/current/lib/delayed_job_cron_jobs/create_delayed_job.rb
--model "Test" --method "remove_old_unpublished" --queue "general"
--arguments "{:any_argument => 42}"

the following gist is a script to insert delayed_jobs from cron
https://gist.github.com/jshow/5228049

fyi, the reason to take this route over the simpler rake route (run rake
task from cron) is performance and memory usage - this method will save you
a bunch of both.

Jodi

On Sat, Mar 23, 2013 at 10:10 AM, Barry <[email protected]> wrote:

> Hi, I faced such issue - my app should run some delayed method.
> For example, I have Test model, which User can create. But to other users
> it should be visible only if it has :saved value in status attribute, which
> is assigned with special button.
> I want to delete all tests, which remained unpublished 24 hours after
> creating.
> And really don't know where to start. Found Rails episode 'Delayed Jobs',
> but it is not what I'm looking for, it is mostly about background methods.
> Can you give me any keys to topic, from where I can begin digging by
> myself?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msg/rubyonrails-talk/-/TO1j6Ma67TYJ.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to