sidekiq_middlewares 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 58d19e122710ee61085ace66515a1f856e6303d9
4
+ data.tar.gz: 184c9d55a540287db3d3fa870681afe9199da7bd
5
+ SHA512:
6
+ metadata.gz: d29cddfc92e9aec4dde97bfdce4f49f84c893f1b37d2e2abe72b0d6f7810bd28b8e7d603cd51334da966d4069a016034de99a6149b3c495e8bffab406b159ee8
7
+ data.tar.gz: 8d922e12bb3c3ccf27368d37dc55e3904d00565849fa096d1cad0c1cc2bdc379e305b82c13074cae41167ae73527a9f33ccb7accd4ad1157384d58de038d94d3
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,33 @@
1
+ language: ruby
2
+ script: rspec spec -f d
3
+
4
+ install:
5
+ - gem update bundler
6
+ - bundle install
7
+
8
+ rvm:
9
+ - 1.9
10
+ - 2.0.0
11
+ - 2.1.1
12
+ - 2.1.2
13
+ - 2.2.2
14
+ - 2.3.1
15
+ - 2.4.1
16
+ - jruby-19mode
17
+
18
+ - ruby-head
19
+ - jruby-head
20
+
21
+ matrix:
22
+ allow_failures:
23
+ - rvm: ruby-head
24
+ - rvm: jruby-head
25
+
26
+ env:
27
+ global:
28
+ - VERBOSE=true
29
+ - TIMEOUT=1
30
+
31
+ branches:
32
+ only:
33
+ - master
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at adamluzsi@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sidekiq_middlewares.gemspec
4
+ gemspec
@@ -0,0 +1,38 @@
1
+ # sidekiq_middlewares
2
+ [![Build Status](https://travis-ci.org/emartech/sidekiq_middlewares.svg?branch=master)](https://travis-ci.org/emartech/sidekiq_middlewares)
3
+
4
+ Ruby Sidekiq Middlewares For common uses
5
+
6
+ ### Benchmarker
7
+
8
+ #### Optiosn
9
+ * logger
10
+ * required
11
+ * this will be the object that must respond to :info method
12
+ * formatter
13
+ * optional
14
+ * this proc will receive one argument, a message object which is a Hash type
15
+ * If the logger can handle Hash messages, such as TwP's [logging](https://github.com/TwP/logging) libary, than you don't need this
16
+
17
+ ```ruby
18
+ require 'json'
19
+ require 'logger'
20
+
21
+ require 'json'
22
+ require 'logger'
23
+
24
+ json_logger = Logger.new(STDOUT)
25
+ json_logger.formatter = proc do |severity, datetime, progname, msg|
26
+ JSON.dump(msg) + "\n"
27
+ end
28
+
29
+ Sidekiq.configure_server do |config|
30
+ config.redis = sidekiq_redis_config
31
+
32
+ config.server_middleware do |chain|
33
+ chain.add SidekiqMiddlewares::Benchmarker, logger: json_logger
34
+ # or
35
+ # chain.add SidekiqMiddlewares::Benchmarker, logger: Logger.new(STDOUT), formatter: proc { |m| JSON.dump(m) + "\n" }
36
+ end
37
+ end
38
+ ```
@@ -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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sidekiq_middlewares"
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(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,4 @@
1
+ require "sidekiq_middlewares/version"
2
+ module SidekiqMiddlewares
3
+ autoload :Benchmarker, "sidekiq_middlewares/benchmarker"
4
+ end
@@ -0,0 +1,35 @@
1
+ require 'benchmark'
2
+ require 'sidekiq_middlewares'
3
+
4
+ class SidekiqMiddlewares::Benchmarker
5
+
6
+ def initialize(opts = {})
7
+ @logger = opts[:logger] || raise(ArgumentError, 'missing keyword: logger')
8
+ @formatter = opts[:formatter] || proc { |message| message }
9
+ end
10
+
11
+ def call(_worker, job, _queue, &next_middleware_call)
12
+ measurement = Benchmark.measure(&next_middleware_call)
13
+ @logger.info(@formatter.call(message_to_log(job, measurement)))
14
+ end
15
+
16
+ private
17
+
18
+ def message_to_log(job, measurement)
19
+ base_by(job).merge(results_by(measurement))
20
+ end
21
+
22
+ def base_by(job)
23
+ {
24
+ 'jid' => job['jid'],
25
+ 'queue' => job['queue'],
26
+ 'worker_class' => job['class'],
27
+ 'created_at' => job['created_at'],
28
+ 'enqueued_at' => job['enqueued_at']
29
+ }
30
+ end
31
+
32
+ def results_by(measurement)
33
+ { 'execution_time_sec' => measurement.real }
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module SidekiqMiddlewares
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'sidekiq_middlewares/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'sidekiq_middlewares'
9
+ spec.version = SidekiqMiddlewares::VERSION
10
+ spec.authors = ['Emarsys Smart Insight Team']
11
+ spec.email = ['smart-insight-dev@emarsys.com']
12
+
13
+ spec.summary = 'Commonly reused Sidekiq Middlewares such as Benchmarker'
14
+ spec.description = 'Commonly reused Sidekiq Middlewares such as Benchmarker'
15
+ spec.homepage = 'https://github.com/emartech/sidekiq_middlewares'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.14'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sidekiq_middlewares
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Emarsys Smart Insight Team
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Commonly reused Sidekiq Middlewares such as Benchmarker
56
+ email:
57
+ - smart-insight-dev@emarsys.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/sidekiq_middlewares.rb
72
+ - lib/sidekiq_middlewares/benchmarker.rb
73
+ - lib/sidekiq_middlewares/version.rb
74
+ - sidekiq_middlewares.gemspec
75
+ homepage: https://github.com/emartech/sidekiq_middlewares
76
+ licenses: []
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.5.1
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Commonly reused Sidekiq Middlewares such as Benchmarker
98
+ test_files: []