Created
January 16, 2018 16:47
-
-
Save hodak/53278bcef67f08537451d16bf277d754 to your computer and use it in GitHub Desktop.
ruby verk adapter
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
module Verk | |
class Adapter | |
NAMESPACE = "queue" | |
QUEUE = "default" | |
def initialize | |
@redis = Redis.new(url: APP_CONFIG[:redis_url]) | |
end | |
def enqueue(module_name, args) | |
job = verk_job(module_name, args).to_json | |
redis.lpush "#{NAMESPACE}:#{QUEUE}", job | |
end | |
private | |
attr_reader :redis | |
def verk_job(module_name, args) | |
{ | |
args: args, | |
class: "Elixir.#{module_name}", | |
enqueued_at: Time.now.to_i, | |
error_backtrace: nil, | |
error_message: nil, | |
failed_at: nil, | |
finished_at: nil, | |
jid: 19.times.map { rand(10) }.join, | |
max_retry_count: 25, | |
original_json: nil, | |
queue: QUEUE, | |
retried_at: nil, | |
retry_count: 0, | |
} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment