Resque Scheduler无法删除延迟的作业

时间:2015-12-08 23:33:53

标签: ruby-on-rails resque resque-scheduler

我使用Rails 4应用程序运行Resque Scheduler,我发现无法取消排队的作业。我的控制器中有以下方法:

class Employers::SocialMediaPostsController < ApplicationController
    def cancel
        post = SocialMediaPost.find(params[:id])

        respond_to do |format|
            if post.cancel_post && post.destroy
                format.json { render json: {}, status: :ok }
            else
                format.json { render json: {}, status: :bad_request }
            end
        end
    end
end

然后在我的SocialMediaPost模型中,我有以下方法:

def cancel_post
    success = false
    if self.scheduled_time > DateTime.now
        options = {
            id: self.id,
            services: JSON.parse(self.services),
            posts: JSON.parse(self.posts),
            attachment_url: self.attachment_url,
            media_url: self.media_url,
            time: self.scheduled_time.in_time_zone("Eastern Time (US & Canada)")
        }
        success = Resque.remove_delayed(Postman, options) > 0
    end
    success
end

这是我的Postman工作人员:

class Postman
    @queue = :social_media_posts

    def self.perform(options)
        post = SocialMediaPost.find(options['id'])
        post.post_tweet if options['services']['twitter'] && options['attachment_url'].blank?
        post.post_tweet_with_media if options['services']['twitter'] && options['attachment_url'].present?
        post.post_facebook_status if options['services']['facebook']
        post.post_linkedin_status if options['services']['linkedin']
    end
end

当我致电Employers::SocialMediaPostsController#cancel时,它会在我的帖子上成功调用cancel方法然后销毁它,但是如果我检查调度程序中的Delayed标签,我仍然会看到我的帖子排队起来。

如果我打开一个控制台会话并调用以下代码来手动删除帖子,它就会起作用。

post = SocialMediaPost.find(id)
post.cancel_post

我在这里缺少什么?它适用于控制台会话,但不是在我调用API端点时。

0 个答案:

没有答案
相关问题