简体   繁体   English

使用python脚本调度sidekiq作业

[英]scheduling a sidekiq job with a python script

I have sidekiq running with a rails APP. 我有用rails APP运行的sidekiq。 I need to be able to run a job from a python script (as I'm using Luigi to run tasks in general). 我需要能够从python脚本运行作业(因为我通常使用Luigi运行任务)。 I'm searching for a python library to work with the Sidekiq API but so far not luck. 我正在寻找可与Sidekiq API配合使用的python库,但到目前为止还算不上好运。 Any ideas or thoughts about this? 有任何想法或想法吗?

This is the translation to Python: 这是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))

https://github.com/mperham/sidekiq/wiki/FAQ#how-do-i-push-a-job-to-sidekiq-without-ruby https://github.com/mperham/sidekiq/wiki/FAQ#how-do-i-push-a-job-to-sidekiq-without-ruby

This is the simplest Ruby, translate it to Python: 这是最简单的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))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM