https://github.com/emartech/sidekiq_middlewares
Ruby Sidekiq Middlewares For common uses
https://github.com/emartech/sidekiq_middlewares
Last synced: over 1 year ago
JSON representation
Ruby Sidekiq Middlewares For common uses
- Host: GitHub
- URL: https://github.com/emartech/sidekiq_middlewares
- Owner: emartech
- License: mit
- Created: 2017-06-01T12:48:05.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2021-09-15T13:57:25.000Z (almost 5 years ago)
- Last Synced: 2024-04-14T07:41:07.676Z (over 2 years ago)
- Language: Ruby
- Size: 18.6 KB
- Stars: 0
- Watchers: 15
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# sidekiq_middlewares
[](https://travis-ci.org/emartech/sidekiq_middlewares)
Ruby Sidekiq Middlewares For common uses
### Benchmarker
#### Optiosn
* logger
* required
* this will be the object that must respond to :info method
* formatter
* optional
* this proc will receive one argument, a message object which is a Hash type
* If the logger can handle Hash messages, such as TwP's [logging](https://github.com/TwP/logging) libary, than you don't need this
first you need a logger that respond to :info method, and format the message object into an expected format.
For simplicity, in the example this will be json.
```ruby
require 'json'
require 'logger'
json_logger = Logger.new(STDOUT)
json_logger.formatter = proc do |severity, datetime, progname, msg|
JSON.dump(msg) + "\n"
end
```
Than you can use it with the Benchmarker middleware like this:
```ruby
Sidekiq.configure_server do |config|
config.redis = sidekiq_redis_config
config.server_middleware do |chain|
chain.add SidekiqMiddlewares::Benchmarker, logger: json_logger
end
end
```
Or if you don't want to provide logger who also know about how to format, you can give an optional formatter to the middleware.
```ruby
Sidekiq.configure_server do |config|
config.redis = sidekiq_redis_config
config.server_middleware do |chain|
chain.add SidekiqMiddlewares::Benchmarker, logger: Logger.new(STDOUT), formatter: proc { |m| JSON.dump(m) + "\n" }
end
end
```