markbates / dj_remixes

Enhancements and improvements for Delayed Job 2.x
http://www.metabates.com
MIT License
42 stars 12 forks source link

Can't get re_enqueue to work #5

Closed thokra closed 13 years ago

thokra commented 13 years ago

Hi dj_remixes is just what I'm looking for, but I can't get it to work ... I have added it to the Gemfile, and created a lib/feed_updater.rb. Ran the generator, and ran script/delayed_job start Then I opened the rails console, required feed_updater and enqueued it. It run after a minute, but then it disappears from the table, it's not readded. When I tried to enqueue it the first time, worker_class_name and finished_at was missing from the database. I added them as string and datetime.

This is my current class:

class UpdateFeeds < DJ::Worker
  re_enqueue

  def run_at
    1.minute.from_now
  end

  def perform
    puts "HELLO!!"
  end
end

Have I missed some steps?

markbates commented 13 years ago

I don't think you've missed any steps. I use this feature all the time, so it's just a matter of figuring out why it's not working for you. :)

I need to add a generator to add in the dj_remixes columns, but you're delayed_jobs table should look something like this:

https://gist.github.com/739059

Oh, just had a brain storm, are you sure it's still not in the table? When it reenqueue's itself it gets a different ID because it's a new record. DJ deletes jobs from the database when they're done, so to get reenqueueing working without hacking at the core of DJ I simply clone the object and create a new job record for it. Can you check and see if that's what's happening?

thokra commented 13 years ago

Hi, thanks for quick reply. I updated the table to whats in your gist, and retried my approach. It's one row after I have added it manually. Then, after a minute, it's gone, no more rows in the table. If I add another manually, the ID is 2, one more than the last I added. So there is no other added automatically.

Weird stuff going on

markbates commented 13 years ago

What version of DJ are you using?

markbates commented 13 years ago

Try using:

gem 'delayed_job', '2.1.1'

I haven't tested it with the absolute latest version, so it's possible that there's a change that's breaking this behavior.

thokra commented 13 years ago

I've tried both the latest gem and from master (Copy/paste the gem .. from your readme)

markbates commented 13 years ago

Try 2.1.1 and see if that works.

thokra commented 13 years ago

Hm .. No change.

markbates commented 13 years ago

Hmm... bizarre. Try use rake jobs:work instead of the binary and see if there's any change. Also, as stupid as this sounds, make sure you're restarting both your rails env and the workers when you make changes to your Gemfile. I know, it's dumb thing to say, but sometimes we all forget the little steps. :)

thokra commented 13 years ago

No change. Tried to create a fresh rails app, and it didn't help. https://gist.github.com/739096 <- that's my test worker.

markbates commented 13 years ago

That's really weird! You're worker worked just fine for me, no problems at all. Can gist you both your Gemfile and your Gemfile.lock so we can see what's up?

thokra commented 13 years ago

Hm .. My Gemfile: https://gist.github.com/739104 Gemfile.lock https://gist.github.com/739103

markbates commented 13 years ago

What version of Ruby? I wonder if that's it? I'm using 1.9.2. What are you using?

thokra commented 13 years ago

I have tried with ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0]

ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10.5.0]

and

ruby 1.8.7 (2010-04-19 patchlevel 253) [i686-darwin10.5.0], MBARI 0x6770, Ruby Enterprise Edition 2010.02

markbates commented 13 years ago

I just created a brand new Rails 3 project using your Gemfiles and it worked like a charm for me. If you give me an email I can zip up the project and send it your way to check out. Also, if you want to zip up your test project and send it my way, that might help to diagnose it.

markbates commented 13 years ago

Ok, having seen your project, I think I figured out your problems.

1.) You need to add lib to your autoloads. In application.rb add the following:

config.autoload_paths += %W(#{config.root}/lib)

2.) Change the name of the file container the worker to update_feeds.rb instead of worker.rb. Rails works best when you use the convention of file name to class name.

Now try it. Once I did that everything seems to be working just fine for me.

Oh, and remove the lines that are doing the enqueuing in the file itself, and just try it manually in the console.

Let me know how that works for you.

thokra commented 13 years ago

THANKS! Worked like a charm! And the latest comments there, just my laziness ;) But thanks a lot!

markbates commented 13 years ago

Whew! Glad it's all working now. Have fun!