-
Notifications
You must be signed in to change notification settings - Fork 31
Getting Started
Faktory::Job is a module which provides an API very similar to the Sidekiq::Worker API. You include the module in every background job class.
class SomeJob
include Faktory::Job
faktory_options queue: "critical", custom: { unique_for: 10.minutes }
def perform(*args)
end
end
SomeJob.perform_async(1, 2, "bob")
SomeJob.perform_in(5.minutes, 1, 2, "bob")
# use `set` to dynamically override or set options
SomeJob.set(custom: { unique_for: nil }).perform_in(5.minutes, 1, 2, "bob")Faktory::Client provides a low-level API for creating background jobs and accessing other Faktory commands. You typically won't need to use this API unless you are doing something unusual.
By default, the Faktory ruby API will connect to localhost:7419. Use FAKTORY_PROVIDER and FAKTORY_URL variables to define any custom Faktory location.
# FAKTORY_URL=tcp+tls://faktory.example.com:7419 bundle exec rails server ...
# FAKTORY_PROVIDER=SOME_FAKTORY_URL SOME_FAKTORY_URL=tcp+tls://faktory.example.com:7419 bundle exec rails server ...Instantiating a client will find and use those ENV variables. You need to set those variables for any Ruby process which uses Faktory.
c = Faktory::Client.new
c = Faktory::Client.new(debug: true) # logs any network protocol chatterThis will create an open connection. Be sure to close it or use the Faktory.server helper which uses a connection pool internally so it will be much faster:
# good
c = Faktory::Client.new
result = begin
c.info
ensure
c.close
end
# better
result = Faktory.server { |c| c.info }Use push(job_hash) to push a job to Faktory. There's 3-4 required elements for the hash. This is a good API to use if you are creating jobs to be processed by another language (e.g. python, go, node).
c.push({
"jobtype" => "foo",
"queue" => "critical",
"retry" => 10,
"args" => [1, 2, "Some String"],
"custom" => { ... }
})Read through faktory/client for the actual implementation.