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

(hooks) Job initialize called on create #35

Closed
gregory-m opened this issue Nov 24, 2011 · 2 comments
Closed

(hooks) Job initialize called on create #35

gregory-m opened this issue Nov 24, 2011 · 2 comments

Comments

@gregory-m
Copy link
Contributor

Hi.

In hooks branch you suggest to move all finders into job initialize method, and only this method will get arguments.

But you call initialize on job creation, so this will double my DB queries. Yes I can do some thing like this:


class ProcessPresentation < Qu::Job
  def initialize(presentation_id)
    @presentation_id = presentation_id
  end

  def perform
     Presentation.find(@presentation_id).process!
  end
end

But this looks like a hack for me.

@bkeepers
Copy link
Owner

This is something that I debated in my head about for a long time and still don't feel satisfied with the solution yet. My goal was to have the job in the same state for any of the hooks. Unfortunately, as you point out, that means that it may have to do lookups for the enqueue hooks.

By passing the args to initialize, people can do whatever they want with them.

I also kicked around the idea of making the Job class act like a struct:

class ProcessPresentation < Qu::Job.new(:presentation_id)
  def perform
     Presentation.find(presentation_id).process!
  end
end

In the end, I decided that it didn't feel right, and I'd rather keep jobs as close to a normal Ruby object as possible.

I'm open to suggestions.

@jnunemaker
Copy link
Collaborator

This is what I typically do and what I would recommend once hooks branch lands:

class ProcessPresentation < Qu::Job
  def initialize(presentation_id)
    @presentation_id = presentation_id
  end

  def presentation
    @presentation ||= Presentation.find(@presentation_id)
  end

  def perform
    presentation.process!
  end
end

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

3 participants