通过 Rails 控制台在 resque 中查找计划的延迟作业

问题描述 投票:0回答:1

在 Rails 中,我们可以轻松地让工作人员了解情况。我使用 resque-schedule 来实现延迟作业目的,现在我想通过 Rails 控制台获取所有延迟作业列表。

ruby-on-rails redis resque resque-scheduler
1个回答
0
投票

我找到了解决方案,它对我很有帮助

Resque.delayed_queue_peek(1, 20)
# Result : ["1727744400", "1727780400", "1728379910", "1728381061", "1728381063", "1728381750", "1728383426", "1728391401", "1728391426", "1730320200", "1731148380", "1737030600"]


scheduled_timestamps = Resque.redis.zrange('delayed_queue_schedule', 0, -1)
# result  ["1727744400", "1727780400", "1728379910", "1728381061", "1728381063", "1728381750", "1728383426", "1728391401", "1728391426", "1730320200", "1731148380", "1737030600"]

scheduled_jobs = scheduled_timestamps.map do |timestamp|
   Resque.redis.lrange("delayed:#{timestamp}", 0, -1)
end
# result [["{\"class\":\"CompanyEnqueSnapshotsJob\",\"args\":[1,\"2024-10-01\"],\"queue\":\"snapshots\"}"]...

scheduled_jobs.flatten.each do |job|
   puts job
end
{"class":"CompanyEnqueSnapshotsJob","args":[1,"2024-10-01"],"queue":"snapshots"}

谢谢你

© www.soinside.com 2019 - 2024. All rights reserved.