使用 python 脚本安排 sidekiq 作业
scheduling a sidekiq job with a python script
我有sidekiq运行一个railsAPP。我需要能够从 python 脚本 运行 完成一份工作(因为我通常使用 Luigi 来完成 运行 任务)。我正在寻找一个 python 库来与 Sidekiq API 一起工作,但到目前为止还不太顺利。对此有什么想法或想法吗?
https://github.com/mperham/sidekiq/wiki/FAQ#how-do-i-push-a-job-to-sidekiq-without-ruby
这是最简单的Ruby,翻译成Python:
require 'securerandom'
require 'json'
redis = Redis.new(:url => 'redis://hostname:port/db')
msg = { "class" => 'MyWorker',
"queue" => 'default',
"args" => [1, 2, 3],
'retry' => true,
'jid' => SecureRandom.hex(12),
'created_at' => Time.now.to_f,
'enqueued_at' => Time.now.to_f }
redis.lpush("queue:default", JSON.dump(msg))
这是 Python 的翻译:
import redis
import json
from random import choice
from datetime import datetime
sidekiq_queues = redis.Redis(host=host, port=port, db=db, password=password)
queue = 'my_queue'
job = 'MyJob'
arguments = 123456789
value = {
"class": job,
"queue": queue,
"args": [arguments],
"retry": 'true',
"jid": ''.join([choice('qwertyuiopasdfghjklzxcvbnm1234567890') for i in range(24)]),
"created_at": datetime.now().timestamp(),
"enqueued_at": datetime.now().timestamp()}
sidekiq_queues.sadd(f"queues", queue)
sidekiq_queues.lpush(f"queue:{queue}" , json.dumps(value))
我有sidekiq运行一个railsAPP。我需要能够从 python 脚本 运行 完成一份工作(因为我通常使用 Luigi 来完成 运行 任务)。我正在寻找一个 python 库来与 Sidekiq API 一起工作,但到目前为止还不太顺利。对此有什么想法或想法吗?
https://github.com/mperham/sidekiq/wiki/FAQ#how-do-i-push-a-job-to-sidekiq-without-ruby
这是最简单的Ruby,翻译成Python:
require 'securerandom'
require 'json'
redis = Redis.new(:url => 'redis://hostname:port/db')
msg = { "class" => 'MyWorker',
"queue" => 'default',
"args" => [1, 2, 3],
'retry' => true,
'jid' => SecureRandom.hex(12),
'created_at' => Time.now.to_f,
'enqueued_at' => Time.now.to_f }
redis.lpush("queue:default", JSON.dump(msg))
这是 Python 的翻译:
import redis
import json
from random import choice
from datetime import datetime
sidekiq_queues = redis.Redis(host=host, port=port, db=db, password=password)
queue = 'my_queue'
job = 'MyJob'
arguments = 123456789
value = {
"class": job,
"queue": queue,
"args": [arguments],
"retry": 'true',
"jid": ''.join([choice('qwertyuiopasdfghjklzxcvbnm1234567890') for i in range(24)]),
"created_at": datetime.now().timestamp(),
"enqueued_at": datetime.now().timestamp()}
sidekiq_queues.sadd(f"queues", queue)
sidekiq_queues.lpush(f"queue:{queue}" , json.dumps(value))