在 Rails 中,我们可以轻松地让工作人员了解情况。我使用 resque-schedule 来实现延迟作业目的,现在我想通过 Rails 控制台获取所有延迟作业列表。
我找到了解决方案,它对我很有帮助
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"}
谢谢你