Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveRecord Callbacks not firing properly on workers #780

Closed
jeremycw opened this issue Dec 17, 2012 · 1 comment
Closed

ActiveRecord Callbacks not firing properly on workers #780

jeremycw opened this issue Dec 17, 2012 · 1 comment

Comments

@jeremycw
Copy link

I have a job that basically boils down to this:

def self.perform()
  [100, 30, 14, 5, 2, 3, 1, 1, 1].each do |delay|
    sleep(delay)
    Foo.create
  end
end

At first I had a FooObserver that looked something like this:

FooObserver < ActiveRecord::Observer
  def after_commit(foo)
    do_important_stuff()
  end
end

But I noticed that do_important_stuff was never getting called even though I could see that Foo records were being created.

Then I tried:

Foo < ActiveRecord::Base
  after_commit :do_important_stuff

  #...
end

This way do_important_stuff is firing everytime except the very last time. I figured that maybe the job was terminating before that callback was getting fired. So I added a 5 second sleep to the end of self.perform but still no luck. Any ideas what's going on?

@steveklabnik
Copy link
Member

No clue. Just so you know, we've extracted Observers to a plugin in Rails 4 because we consider them to be not a good idea, generally speaking.

I think you should file this bug over at https://github.com/rails/rails-observers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants