Last active
November 4, 2021 09:29
-
-
Save labocho/3615890990eb06a64039c8e28e448d4d to your computer and use it in GitHub Desktop.
Adding ActiveJob job for resque without activejob gem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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