Nikita Fedyashev
Nikita Fedyashev

Reputation: 19048

How to get return value from Que::Job .run call?

Is there a way to run(immediately/synchronously) Que job and get what its run method returns?

class FooJob < Que::Job
  def run
    puts "FooJob is called"
    123
  end
end

supposedly_return_value = FooJob.run # expected 123?
supposedly_return_value.class # => FooJob
supposedly_return_value.class.superclass # => Que::Job

Before switching to Que I found this feature really helpful in very rare use cases in ActiveJob.

Upvotes: 0

Views: 39

Answers (1)

Nikita Fedyashev
Nikita Fedyashev

Reputation: 19048

As a workaround, this is what I did:

class FooJob < Que::Job
  def run(some_id)
    self.class.run_and_return(some_id)
  end

  def self.run_and_return(some_id)
    puts "FooJob is called"
    123
  end
end

# just use `FooJob.run_and_return(some_id)` instead of `FooJob.run(some_id)` 
# whenever you need to call a job synchronously and get return value

Upvotes: 0

Related Questions