取消预定作业的列表

取消预定作业的列表

本文介绍了sidekiq 取消预定作业的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个这样运行的预定作业:

I have several scheduled jobs running like this:

MyWorker.perform_at(3.hours.from_now, 'mike', 1)

我想知道,如果晚一点,说一个小时后,我想取消这份工作,我该怎么做?

I am wondering, if later, say an hour later, I feel like I want to cancel this job, how would I go about doing that?

推荐答案

我最近编写了一些代码来处理这个问题,它可以在我的 sidekiq-status gem 分支中找到.您可以在此处查看或使用它:https://github.com/Robinson7D/sidekiq-status

I've recently written a bit of code to handle this, it's available in my branch of the sidekiq-status gem. You can view it, or use it here:https://github.com/Robinson7D/sidekiq-status

(您必须将其用作 gemfile 中的 git: 信息,目前,直到项目的主分支实现此为止)

(You would have to use that as the git: information in the gemfile, currently, until the main fork of the project implements this)

要使用它,首先要存储 job_identifier:

To use it, first you store the job_identifier:

job_identifier = MyWorker.perform_at(3.hours.from_now, 'mike', 1)

当你想销毁它时,你调用 Sidekiq::Status.cancel 方法:

And when you wish to destroy it you call the Sidekiq::Status.cancel method:

Sidekiq::Status.cancel job_identifier

自从写这篇文章以来,我的代码已被 Sidekiq::Status 的主分支接受 - https://github.com/utgarda/sidekiq-status.你不再需要使用我的叉子了.在 Utgarda 的 fork 上,您将通过调用 unschedule 而不是取消来触发它:

since writing this post, my code's been accepted into the main fork of Sidekiq::Status - https://github.com/utgarda/sidekiq-status . You no longer have to use my fork. On Utgarda's fork you would trigger it by calling unschedule, instead of cancel:

Sidekiq::Status.unschedule job_identifier

此外:您还可以使用标准 Sidekiq gem 删除作业,如下所述:https://github.com/mperham/sidekiq/wiki/API(尽管对于他们的方法,您需要计划作业的 unix 时间戳 - 您不能仅使用作业的 ID 进行删除;如果您希望删除没有时间戳的作业,则Sidekiq::Status 方法可能适合您).

Further: you can also delete jobs using the standard Sidekiq gem as explained here: https://github.com/mperham/sidekiq/wiki/API (though for their methods you require the unix-timestamp of when the job is scheduled for - you cannot delete with only the job's id; if you wish to delete a job without the timestamp, the Sidekiq::Status method may be right for you).

然而,如果你只想删除,我会推荐一些类似于 Sidekiq::ScheduledSet.new().delete(unix_timestamp, jid) 的内容,而不是他们在 wiki 中概述的方式一份工作.)

However, instead of the ways they outline in the wiki I would recommend something along the lines of Sidekiq::ScheduledSet.new().delete(unix_timestamp, jid) if you want to delete just one job.)

这篇关于sidekiq 取消预定作业的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 04:59