Skip to content

Instantly share code, notes, and snippets.

@labocho
Last active November 4, 2021 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save labocho/3615890990eb06a64039c8e28e448d4d to your computer and use it in GitHub Desktop.
Save labocho/3615890990eb06a64039c8e28e448d4d to your computer and use it in GitHub Desktop.
Adding ActiveJob job for resque without activejob gem
#!/usr/bin/env ruby
#
# Adding ActiveJob job without activejob gem example.
# For job class like:
# class FooJob < ApplicationJob
# queue_as :foo
#
# def perform(a, b)
# puts a, b
# end
# end
require "json"
require "redis"
require "securerandom"
def register_job(redis, queue_name, job_class_name, arguments)
job = {
"class": "ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper",
"args": [
{
"job_class": job_class_name,
"job_id": SecureRandom.uuid,
"queue_name": queue_name,
"priority": nil,
"arguments": arguments,
"locale": "ja"
}
]
}
redis.sadd("resque:queues", queue_name)
redis.rpush("resque:queue:#{queue_name}", job.to_json)
end
redis = Redis.new(host: "127.0.0.1")
register_job(redis, "foo", "FooJob", ["foo", "bar"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment