delayed_job_slack_notification 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9c6c7206432a762287005e04bba3814cad84e254
4
+ data.tar.gz: f95b8a084659f24172ab1553540deea0e998daf4
5
+ SHA512:
6
+ metadata.gz: 034ab7eaa80e8a81dfab0b602bd5d07ea83ccb0654da0adf40ead3283829c2d6cbce8ae3262b0194f8e40e46664856105fcb74138fe2003cb410dd79125e6ce1
7
+ data.tar.gz: 5c433fa4845e7af86dbf101234d05d19c842fe25ab23cee43deb589dd620e1b3a0897ee08deb87e182ef1011b127b93c51ce293cffb4ca0ba7457f64a92abd11
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in delayed_job_slack_notification.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # DelayedJobSlackNotification
2
+
3
+ Simple job count notification on slack
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'delayed_job_slack_notification'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install delayed_job_slack_notification
20
+
21
+ ## Usage
22
+
23
+ You need to put following configuration to ```config/initializers/delayed_job_slack_notification.rb```
24
+
25
+ ```ruby
26
+ DelayedJobSlackNotification.webhook_url = "https://hooks.slack.com/services/your/hook"
27
+ DelayedJobSlackNotification.channel = "#general"
28
+ DelayedJobSlackNotification.username = "Delayed Job"
29
+ ```
30
+
31
+ and run ```rake job:notification```
32
+
33
+ ## Development
34
+
35
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
36
+
37
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it ( https://github.com/hsbt/delayed_job_slack_notification/fork )
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "delayed_job_slack_notification"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'delayed_job_slack_notification/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "delayed_job_slack_notification"
8
+ spec.version = DelayedJobSlackNotification::VERSION
9
+ spec.authors = ["SHIBATA Hiroshi"]
10
+ spec.email = ["hsbt@ruby-lang.org"]
11
+
12
+ spec.summary = %q{Slack notifier for pending jobs of Delayed Job.}
13
+ spec.description = %q{Slack notifier for pending jobs of Delayed Job.}
14
+ spec.homepage = "https://github.com/hsbt/delayed_job_slack_notification"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "delayed_job_active_record"
22
+ spec.add_dependency "slack-notifier"
23
+ spec.add_dependency "activesupport"
24
+
25
+ spec.add_development_dependency "bundler"
26
+ spec.add_development_dependency "rake"
27
+ end
@@ -0,0 +1,10 @@
1
+ require "delayed_job_slack_notification/version"
2
+
3
+ require 'slack-notifier'
4
+ require 'active_support/all'
5
+
6
+ module DelayedJobSlackNotification
7
+ mattr_accessor :webhook_url, :channel, :username
8
+ end
9
+
10
+ require "delayed_job_slack_notification/railtie" if defined?(Rails)
@@ -0,0 +1,7 @@
1
+ module DelaydJobSlackNotification
2
+ class Railtie < Rails::Railtie
3
+ rake_tasks do
4
+ load "tasks/delayed_job_slack_notification.rake"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module DelayedJobSlackNotification
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,24 @@
1
+ require 'delayed_job_active_record'
2
+ require 'net/http'
3
+ require 'json'
4
+
5
+ namespace :jobs do
6
+ desc 'DJ のジョブが貯まっていたら slack で通知する'
7
+ task notification: :environment do
8
+ pending_jobs = Delayed::Job.where(:attempts => 0, :locked_at => nil).count
9
+
10
+ if pending_jobs >= 50
11
+ alert = "[CRIT] ジョブが #{pending_jobs} 件残っています。ワーカーの状況を確認してください。"
12
+ icon = ":critical:"
13
+ elsif pending_jobs >= 20
14
+ alert = "[WARN] ジョブが #{pending_jobs} 件残っているようです。"
15
+ icon = ":warning:"
16
+ end
17
+
18
+ if alert && icon
19
+ uri = URI.parse(DelayedJobSlackNotification.webhook_url)
20
+ params = {'payload' => {"channel" => DelayedJobSlackNotification.channel, "username" => DelayedJobSlackNotification.username, "text" => alert, "icon_emoji" => icon}.to_json}
21
+ Net::HTTP.post_form(uri, params)
22
+ end
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: delayed_job_slack_notification
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - SHIBATA Hiroshi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-05-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: delayed_job_active_record
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: slack-notifier
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Slack notifier for pending jobs of Delayed Job.
84
+ email:
85
+ - hsbt@ruby-lang.org
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - README.md
94
+ - Rakefile
95
+ - bin/console
96
+ - bin/setup
97
+ - delayed_job_slack_notification.gemspec
98
+ - lib/delayed_job_slack_notification.rb
99
+ - lib/delayed_job_slack_notification/railtie.rb
100
+ - lib/delayed_job_slack_notification/version.rb
101
+ - lib/tasks/delayed_job_slack_notification.rake
102
+ homepage: https://github.com/hsbt/delayed_job_slack_notification
103
+ licenses: []
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.4.6
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Slack notifier for pending jobs of Delayed Job.
125
+ test_files: []
126
+ has_rdoc: