Sha256: 04b83f5bdee71a6cdadc502a283bd31b09396aa6cc2da961ffa9abc4621dce28

Contents?: true

Size: 934 Bytes

Versions: 3

Compression:

Stored size: 934 Bytes

Contents

require 'delayed_job_active_record'
require 'net/http'
require 'json'

namespace :jobs do
  desc 'DJ のジョブが貯まっていたら slack で通知する'
  task notification: :environment do
    pending_jobs = Delayed::Job.where(:attempts => 0, :locked_at => nil).count

    if pending_jobs >= 50
      alert = "[CRIT] ジョブが #{pending_jobs} 件残っています。ワーカーの状況を確認してください。"
      icon = ":critical:"
      elsif pending_jobs >= 20
        alert = "[WARN] ジョブが #{pending_jobs} 件残っているようです。"
        icon = ":warning:"
    end

    if alert && icon
      uri = URI.parse(DelayedJobSlackNotification.webhook_url)
      params = {'payload' => {"channel" => DelayedJobSlackNotification.channel, "username" => DelayedJobSlackNotification.username, "text" => alert, "icon_emoji" => icon}.to_json}
      Net::HTTP.post_form(uri, params)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
delayed_job_slack_notification-0.1.2 lib/tasks/delayed_job_slack_notification.rake
delayed_job_slack_notification-0.1.1 lib/tasks/delayed_job_slack_notification.rake
delayed_job_slack_notification-0.1.0 lib/tasks/delayed_job_slack_notification.rake