Inserting Oban jobs from Rails is extremely easy. Here is the entirety of the rails model that we have defined:
class ObanJob < ApplicationRecord
self.ignored_columns = %w[errors]
# A simple wrapper around `create`
def self.insert(worker:, args: {}, queue: 'default', scheduled_at: nil)
create(
worker: worker,
queue: queue,
args: args,
scheduled_at: scheduled_at || Time.now.utc,
state: scheduled_at ? 'scheduled' : 'available'
)
end
validates :queue, presence: true
validates :worker, presence: true
end
That’s all it takes for the model. Then you can insert new jobs like this:
ObanJob.insert(worker: “MyApp.Worker”, args: { id: 1 })
Some other options are supported in the helper, but not all of them. It’s easy to switch from names args to a hash is you want to support other things like max_attempts.
We insert jobs freely from the Rails side and it works very well. You don’t get multi or unique support, but it helps bridge the gap.