# DJ: Delayed Job Noob Question

**URL:** <https://www.ruby-forum.com/t/dj-delayed-job-noob-question/185078>\
**Category:** Rails\
**Created:** [March 13, 2010, 2:22am UTC](https://www.ruby-forum.com/t/dj-delayed-job-noob-question/185078 "2010-03-13T02:22:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kampers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/54ee81/32.png) [@kampers](https://www.ruby-forum.com/u/kampers)\
**Post date:** [March 13, 2010, 2:22am UTC](https://www.ruby-forum.com/t/dj-delayed-job-noob-question/185078/1 "2010-03-13T02:22:55Z")

</div>

Hi guys: just got into Rails about a month ago and an about to launch  
something.

I use Heroku and they limit the execution time of pages to 30 seconds. i  
have a process which takes a lot longer than that. So i’m trying to do a  
delayed job.

The docs on delayed job must be for the pros out there cause I can’t  
seem to find out the answers to a few simple questions…

- where do i put the file with the job in it
- what do i name it
- how do i call it
- how do I put it in the queue
- can I run it say, every 5 minutes?

Anyways, hope someone out there can help me out…

Thanks…Chris

---

<div class="post-metadata">

**Author:** ![kampers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/54ee81/32.png) [@kampers](https://www.ruby-forum.com/u/kampers)\
**Post date:** [March 16, 2010, 4:33pm UTC](https://www.ruby-forum.com/t/dj-delayed-job-noob-question/185078/2 "2010-03-16T16:33:07Z")

</div>

Chris K. wrote:

> Hi guys: just got into Rails about a month ago and an about to launch  
> something.
> 
> I use Heroku and they limit the execution time of pages to 30 seconds. i  
> have a process which takes a lot longer than that. So i’m trying to do a  
> delayed job.
> 
> The docs on delayed job must be for the pros out there cause I can’t  
> seem to find out the answers to a few simple questions…
> 
> - where do i put the file with the job in it
> - what do i name it
> - how do i call it
> - how do I put it in the queue
> - can I run it say, every 5 minutes?
> 
> Anyways, hope someone out there can help me out…
> 
> Thanks…Chris

This railscast should answer your first few questions -

> **[\#171 Delayed Job - RailsCasts](http://railscasts.com/episodes/171-delayed-job)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

I’m using DJ on Heroku and I’m running jobs in a recurring fashion. I  
kick things off from the console. I just call some methods that I wrote  
that do nothing but enqueue some jobs. I have the recurring jobs  
re-enqueue themselves upon completion. Here’s an example:

def enqueue\_media\_cleanup  
#this is what I run from the Heroku console  
Delayed::Job.enqueue ClearOldEventsJob.new(), 0, 15.minutes.from\_now  
Delayed::Job.enqueue DumpOldMediaJob.new(), 0, 2.minutes.from\_now  
end

def purge\_expired\_events

#some code to do some stuff…

#ClearOldEventsJob just runs/calls purge\_expired\_events  
Delayed::Job.enqueue ClearOldEventsJob.new(), 0, 6.hours.from\_now

end

There are other ways to do it but this has been working well for me.
