sidekiq_hero 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
+ SHA256:
3
+ metadata.gz: 95f22a1885f5b4c34c76d75b59e111570f69fe3ab59da2baa1609025bd1b91c3
4
+ data.tar.gz: 6fd444444c2a4b5d17d5cf5df2aedbe8f83402a3da8881f5ed761224050eb1a8
5
+ SHA512:
6
+ metadata.gz: 30d4e80644ccc5e1cdbff03eecee63c8f8114b918b4bef0cc8b039bb1e859d7868986551772dec345ab0697c5938a5ac3c84b34612de0217810fea2b6706d76e
7
+ data.tar.gz: 47a6cc6564643e10b494480ab693503fe945c6d06b665c5205da0167d42a961c7752bc1966f43e7fdec105c0ec0ebfc136d3b7dae49c774938a2ce77e2df5868
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /dummy_app/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ .byebug_history
14
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.0
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in sidekiq_hero.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,48 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sidekiq_hero (0.1.0)
5
+ sidekiq (>= 3.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ connection_pool (2.2.2)
11
+ diff-lcs (1.3)
12
+ rack (2.0.6)
13
+ rack-protection (2.0.5)
14
+ rack
15
+ rake (10.5.0)
16
+ redis (4.1.0)
17
+ rspec (3.8.0)
18
+ rspec-core (~> 3.8.0)
19
+ rspec-expectations (~> 3.8.0)
20
+ rspec-mocks (~> 3.8.0)
21
+ rspec-core (3.8.0)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-expectations (3.8.2)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.8.0)
26
+ rspec-mocks (3.8.0)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.8.0)
29
+ rspec-support (3.8.0)
30
+ sidekiq (5.2.5)
31
+ connection_pool (~> 2.2, >= 2.2.2)
32
+ rack (>= 1.5.0)
33
+ rack-protection (>= 1.5.0)
34
+ redis (>= 3.3.5, < 5)
35
+ timecop (0.9.1)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ bundler (~> 1.16)
42
+ rake (~> 10.0)
43
+ rspec (~> 3.0)
44
+ sidekiq_hero!
45
+ timecop
46
+
47
+ BUNDLED WITH
48
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Samuel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # SidekiqHero
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sidekiq_hero`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sidekiq_hero'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sidekiq_hero
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sidekiq_hero.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SidekiqHero
4
+ class Configuration
5
+ attr_accessor :notifier_server_message_class, :exceed_maximum_time
6
+
7
+ def initialize
8
+ @notifier_server_message_class = SidekiqHero::Notifier.new
9
+ @exceed_maximum_time = 0
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SidekiqHero
4
+ class Notifier
5
+
6
+ def self.notify(job, meta_data)
7
+ new.notify(job, meta_data)
8
+ end
9
+
10
+ def notify(job, meta_data)
11
+ Sidekiq.logger.info "#{job} -- #{meta_data}"
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SidekiqHero
4
+ class Recorder
5
+ attr_reader :meta_data
6
+
7
+ def initialize
8
+ @meta_data = {}
9
+ end
10
+
11
+ def record(hash)
12
+ meta_data.merge!(hash)
13
+ end
14
+
15
+ def record_elapsed_time
16
+ total = meta_data.fetch(:ended_at, 0) - meta_data.fetch(:started_at, 0)
17
+ record(total_time: total)
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SidekiqHero
4
+ class ServerMiddleware
5
+ def call(_worker, job, _queue)
6
+ recorder.record(status: 'passed', started_at: Time.now.utc.round)
7
+ yield
8
+ recorder.record(status: 'success')
9
+ rescue => e
10
+ recorder.record(status: 'failed', error: e.to_s)
11
+ raise e
12
+ ensure
13
+ recorder.record(ended_at: Time.now.utc.round)
14
+ recorder.record_elapsed_time
15
+ notifier.notify(job, recorder.meta_data) if exceeded_maximum_time? || job_failed?
16
+ end
17
+
18
+ private
19
+
20
+ def recorder
21
+ @recorder ||= SidekiqHero::Recorder.new
22
+ end
23
+
24
+ def server_message_class
25
+ @server_message_class ||= SidekiqHero.configuration.server_message_class
26
+ end
27
+
28
+ def meta_data
29
+ @meta_data ||= {}
30
+ end
31
+
32
+ def notifier
33
+ SidekiqHero.configuration.notifier_server_message_class
34
+ end
35
+
36
+ def exceed_maximum_time
37
+ @exceed_maximum_time ||= SidekiqHero.configuration.exceed_maximum_time
38
+ end
39
+
40
+ def exceeded_maximum_time?
41
+ recorder.meta_data[:total_time] > exceed_maximum_time
42
+ end
43
+
44
+ def job_failed?
45
+ recorder.meta_data[:status] == 'failed'
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,3 @@
1
+ module SidekiqHero
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sidekiq_hero/version'
4
+ require 'sidekiq/api'
5
+ require 'sidekiq_hero/configuration'
6
+ require 'sidekiq_hero/notifier'
7
+ require 'sidekiq_hero/recorder'
8
+ require 'sidekiq_hero/server_middleware'
9
+
10
+ module SidekiqHero
11
+ class << self
12
+ attr_writer :configuration
13
+ end
14
+
15
+ def self.configuration
16
+ @configuration ||= Configuration.new
17
+ end
18
+
19
+ def self.configure
20
+ yield(configuration)
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "sidekiq_hero/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sidekiq_hero"
8
+ spec.version = SidekiqHero::VERSION
9
+ spec.authors = ["Samuel"]
10
+ spec.email = ["samueljmartini@gmail.com"]
11
+
12
+ spec.summary = ''
13
+ spec.description = ''
14
+ spec.homepage = ''
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features|dummy_app)/})
19
+ end
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'sidekiq', '>= 3.0'
23
+ spec.add_development_dependency "bundler", "~> 1.16"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "timecop"
27
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sidekiq_hero
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Samuel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sidekiq
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: timecop
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: ''
84
+ email:
85
+ - samueljmartini@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - lib/sidekiq_hero.rb
99
+ - lib/sidekiq_hero/configuration.rb
100
+ - lib/sidekiq_hero/notifier.rb
101
+ - lib/sidekiq_hero/recorder.rb
102
+ - lib/sidekiq_hero/server_middleware.rb
103
+ - lib/sidekiq_hero/version.rb
104
+ - sidekiq_hero.gemspec
105
+ homepage: ''
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.7.3
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: ''
129
+ test_files: []