nesquena / backburner

Simple and reliable beanstalkd job queue for ruby
http://nesquena.github.com/backburner
MIT License
430 stars 70 forks source link

Possible to process jobs not enqueued with Backburner? #149

Closed haffla closed 6 years ago

haffla commented 6 years ago

I have a question. I want to enqueue jobs with a Python app and have that job processed by my Rails app. Is that possible in some way? I'm getting

Exception NoMethodError -> undefined method 'perform' for Object:Class

when I put the job on the queue. I figured that this is because the JobClass is not defined since I am not using Backburner to enqueue. I know I can use beaneater but before doing that I wanted to make sure that it is not possible with Backburner.

Thank you

haffla commented 6 years ago

I've found a solution. When I construct the payload in Python like

{"class": "SomeRubyClass", "args": ....}

it actually works, great. Since this is too much coupling I'm going to make use of job_parser_proc with something like this.

config.job_parser_proc = lambda do |body|
  parsed = JSON.parse(body)
  return parsed if parsed.include?(:class) || parsed.include?('class')
  type = parsed[:_job_type] || parsed['_job_type']
  case type
    when 'some_job_type'
      parsed.tap { |prs| prs[:class] = SomeRubyClass }
    else
      raise 'Unknown Job Type'
  end
end

Great gem, thanks!!