### Install Sneakers Gem Manually Source: https://github.com/jondot/sneakers/blob/master/README.md Alternatively, install the Sneakers gem directly using the gem install command. ```Shell Session $ gem install sneakers ``` -------------------------------- ### Bundle Install Sneakers Source: https://github.com/jondot/sneakers/blob/master/README.md Execute the bundle command to install the Sneakers gem after adding it to the Gemfile. ```Shell Session $ bundle ``` -------------------------------- ### Auto Scaling Configuration File Source: https://github.com/jondot/sneakers/wiki/Configuration An example of a `sneakers.conf.rb` file used for auto-scaling. It defines the number of workers and includes `before_fork` and `after_fork` hooks for managing resources during process restarts. ```ruby workers 2 before_fork do Sneakers::logger.info "I'm in a child process!" end after_fork do Sneakers::logger.info " I'm in a child process!" end ``` -------------------------------- ### Run Sneakers Worker Source: https://github.com/jondot/sneakers/blob/master/README.md Start a Sneakers worker from the command line, specifying the worker class and a file to require for setup. ```Shell Session $ sneakers work Processor --require boot.rb ``` -------------------------------- ### Install Sneakers Gem Source: https://github.com/jondot/sneakers/blob/master/README.md Add the Sneakers gem to your application's Gemfile for installation. ```Ruby gem 'sneakers' ``` -------------------------------- ### Sneakers Worker Output with Logging Metrics Source: https://github.com/jondot/sneakers/blob/master/README.md Example output showing metrics like 'started', 'time', and 'handled.ack' when using the logging_metrics provider. ```Shell Session 2013-10-11T19:44:37Z p-9219 t-oxh8owywg INFO: INC: work.Processor.started 2013-10-11T19:44:37Z p-9219 t-oxh8owywg INFO: TIME: work.Processor.time 0.00242 2013-10-11T19:44:37Z p-9219 t-oxh8owywg INFO: INC: work.Processor.handled.ack ``` -------------------------------- ### Project Structure Example Source: https://github.com/jondot/sneakers/wiki/How-to:-running-a-stand-alone-worker Demonstrates a typical project layout for a Ruby gem, including directories for binaries, libraries, and configuration files like Gemfile and Procfile. ```bash $ bundle gem myworker -b $ cd myworker; tree . . ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── bin │ └── myworker ├── lib │ ├── myworker │ │ └── version.rb │ └── myworker.rb └── myworker.gemspec $ tree . . ├── Gemfile ├── LICENSE.txt ├── Procfile ├── README.md ├── Rakefile ├── bin │ └── myworker └── lib ├── myworker │ └── version.rb └── myworker.rb ``` -------------------------------- ### Setup Gemfile for Sneakers Source: https://github.com/jondot/sneakers/wiki/How-To:-Do-Log-Processing This snippet shows the necessary dependencies to include in your Gemfile for using the Sneakers gem, along with JSON and Redis. ```ruby source 'https://rubygems.org' gem 'sneakers' gem 'json' gem 'redis' ``` -------------------------------- ### Run Sample Worker in Docker Source: https://github.com/jondot/sneakers/blob/master/README.md Launches a sample worker, such as 'TitleScraper', using Docker Compose. This demonstrates running Sneakers in a Docker-based production setup. ```bash script/local_worker ``` -------------------------------- ### Run Sneakers Worker from Command Line Source: https://github.com/jondot/sneakers/wiki/How-To:-Do-Log-Processing Command to execute a Sneakers worker. It specifies the worker class and a file to require for setup. ```bash sneakers work Processor --require boot.rb ``` -------------------------------- ### Example Issue Format for Sneakers Contribution Source: https://github.com/jondot/sneakers/wiki/Contributing This snippet shows the expected format for issues created for newcomers to contribute to the Sneakers project. It includes fields for 'Until', 'Difficulty', and a detailed 'Description' with technical pointers. ```Markdown Until: 6-feb-2014 Difficulty: 20min Description of the feature, technical pointers and technical direction for implementing it. ``` -------------------------------- ### Start Sneakers Workers Source: https://github.com/jondot/sneakers/wiki/How-To:-Rails-Background-Jobs Demonstrates the command to start Sneakers workers using the provided rake task. You can specify which worker classes to run by setting the WORKERS environment variable. ```Shell rake sneakers:run ``` ```Shell WORKERS=WebScraper rake sneakers:run ``` -------------------------------- ### Daemon Configuration Options Source: https://github.com/jondot/sneakers/wiki/Configuration Defines various options for controlling the Sneakers daemon's behavior, including log file paths, PID file locations, daemonization, and startup delays for workers. ```ruby :runner_config_file => nil, :metrics => nil, :daemonize => true, :start_worker_delay => 0.2, :workers => 4, :log => 'sneakers.log', :pid_path => 'sneakers.pid' ``` -------------------------------- ### Example Error JSON Payload Source: https://github.com/jondot/sneakers/wiki/How-To:-Do-Log-Processing An example of a JSON-formatted log message representing an error, used for processing by the Sneakers worker. ```javascript { "type": "error", "message": "HALP!", "error": "CODE001" } ``` -------------------------------- ### Example JSON Message for Logging Source: https://github.com/jondot/sneakers/blob/master/README.md A sample JSON payload representing an error message that can be processed by the Sneakers worker. ```JavaScript { "type": "error", "message": "HALP!", "error": "CODE001" } ``` -------------------------------- ### Worker Configuration Options Source: https://github.com/jondot/sneakers/wiki/Configuration Specifies global configuration settings applicable to all Sneakers workers, such as job timeouts, prefetch counts, thread pool size, environment variables, and acknowledgment settings. ```ruby :timeout_job_after => 5, :prefetch => 10, :threads => 10, :env => ENV['RACK_ENV'], :durable => true, :ack => true, :heartbeat => 2, :exchange => 'sneakers', :hooks => {} :start_worker_delay => 10 ``` -------------------------------- ### Configure Worker with Specific Options Source: https://github.com/jondot/sneakers/wiki/Configuration Demonstrates how to configure a specific worker with its own set of options, overriding global settings. This includes queue name, environment, durability, acknowledgment, threads, prefetch, timeout, exchange, and heartbeat. ```ruby class ProfilingWorker include Sneakers::Worker from_queue 'downloads', :env => 'test', :durable => false, :ack => true, :threads => 50, :prefetch => 50, :timeout_job_after => 1, :exchange => 'dummy', :heartbeat => 5 def work(msg) ack! end end ``` -------------------------------- ### Configure Global Sneakers Settings Source: https://github.com/jondot/sneakers/wiki/Configuration Sets global configuration options for Sneakers, such as RabbitMQ connection details like heartbeat, AMQP URL, vhost, and exchange type. This configuration is applied once offline. ```ruby Sneakers.configure :key => value, :otherkey => othervalue ``` ```ruby Sneakers.configure :heartbeat => 30, :amqp => 'amqp://guest:guest@localhost:5672', :vhost => '/', :exchange => 'sneakers', :exchange_type => :direct ``` -------------------------------- ### Set Logger Level Source: https://github.com/jondot/sneakers/wiki/Configuration Configures the logging level for Sneakers. This should be called after the initial `Sneakers.configure` to set the desired verbosity of logs. ```ruby Sneakers.logger.level = Logger::INFO ``` -------------------------------- ### Integrating Sneakers into Sinatra Applications Source: https://github.com/jondot/sneakers/wiki/Home This guide explains how to integrate Sneakers background jobs into a Sinatra application, offering specific considerations for Sinatra-based projects. ```Ruby # Example of integrating Sneakers into a Sinatra application # In your Sinatra app file (e.g., app.rb): require 'sinatra' require 'sneakers' Sneakers.configure( amqp: "amqp://guest:guest@localhost:5672", exchange: "sinatra_app_exchange", exchange_type: :fanout ) # Define your Sneakers worker class SinatraWorker include Sneakers::Worker from_queue :sinatra_queue def work(message) puts "Sinatra worker received: #{message}" # Perform actions relevant to your Sinatra app ack! end end # You might start the worker in a separate thread or process manager # For simplicity, showing a direct run (not recommended for production) # Thread.new { Sneakers::Runner.new([SinatraWorker]).run! } get '/publish' message = { data: 'Hello from Sinatra!' } Sneakers::Publisher.publish(message, to: :sinatra_queue) "Message published!" end # To run this: # 1. Ensure RabbitMQ is running. # 2. Start the Sinatra app. # 3. Access '/publish' in your browser. # 4. Ensure the Sneakers worker is running (e.g., via a process manager). ``` -------------------------------- ### Share Bunny Connection Source: https://github.com/jondot/sneakers/wiki/Configuration Allows Sneakers to use a pre-existing Bunny connection, which is then shared among all workers. This is an optimization for scenarios with a large number of workers to avoid opening multiple connections. ```ruby Sneakers.configure :connection => Bunny.new(…) ``` -------------------------------- ### Running a Stand-alone Worker with Foreman Source: https://github.com/jondot/sneakers/wiki/Home This guide demonstrates how to run a stand-alone Sneakers worker using Foreman, illustrating a modular architecture for background job processing. ```Ruby # Example of a Sneakers worker configuration for Foreman # This is a conceptual example, actual code would be in a separate file. # Assuming a Procfile is used by Foreman: # worker: bundle exec ruby worker.rb # In worker.rb: require 'sneakers' Sneakers.configure( amqp: "amqp://guest:guest@localhost:5672", vhost: "/", exchange: "my_exchange", exchange_type: :direct ) class MyWorker include Sneakers::Worker from_queue :my_queue def work(message) puts "Processing message: #{message}" # Process the message here ack! rescue => e # Handle errors, potentially nack! or requeue nack!(:requeue => true) end end # To run this worker: # 1. Save the worker code in a file (e.g., worker.rb) # 2. Create a Procfile with the content above. # 3. Run 'foreman start' ``` -------------------------------- ### Worker with Publish for Workflow Source: https://github.com/jondot/sneakers/wiki/Creating-a-Worker An advanced Ruby worker example that scrapes a web page title and then publishes the extracted title to a different queue ('title_classification') to enable a workflow. This demonstrates inter-worker communication. ```ruby class TitleScraper include Sneakers::Worker from_queue 'downloads' def work(msg) doc = Nokogiri::HTML(open(msg)) worker_trace "FOUND <#{doc.css('title').text}>" publish(doc.css('title').text, :to_queue => 'title_classification') ack! end end ``` -------------------------------- ### Add Custom Error Reporter Source: https://github.com/jondot/sneakers/wiki/Configuration Enables custom error handling by adding a proc to `Sneakers.error_reporters`. This proc is executed when an exception occurs within a worker, allowing integration with services like Honeybadger. ```ruby Sneakers.error_reporters << proc { |exception, _worker, context_hash| Honeybadger.notify(exception, context_hash) } ``` -------------------------------- ### Integrating Sneakers into Rails Applications Source: https://github.com/jondot/sneakers/wiki/Home This section provides guidance on integrating Sneakers background jobs into a Rails application, covering setup and common patterns for Rails developers. ```Ruby # Example of integrating Sneakers into a Rails application # This typically involves configuring Sneakers and potentially creating initializers. # In config/initializers/sneakers.rb: require 'sneakers' Sneakers.configure( amqp: ENV['RABBITMQ_URL'], # Use environment variable for RabbitMQ connection exchange: 'rails_app_exchange', exchange_type: :topic, # Add other configurations as needed, e.g., workers_path workers_path: Rails.root.join('app', 'workers') ) # Example of a Rails initializer to start Sneakers workers (optional, depending on deployment strategy) # Rails.application.config.after_initialize do # Thread.new do # Sneakers::Runner.new([MyRailsWorker]).run! # end # end # In app/workers/my_rails_worker.rb: class MyRailsWorker include Sneakers::Worker from_queue :rails_queue def work(message) # Access Rails components if needed, e.g., models user_id = message['user_id'] User.find(user_id).send_welcome_email ack! end end # To publish a message from Rails: # Sneakers::Publisher.publish({'user_id' => 123}, to: :rails_queue) ``` -------------------------------- ### Configure Worker Threads and Connection Pools Source: https://github.com/jondot/sneakers/wiki/Auto-scaling This snippet demonstrates how to configure the number of worker threads per process and the database connection pool size. It's crucial for performance tuning, ensuring that the number of threads aligns with the database's connection limits to avoid bottlenecks. For example, setting `:threads => 25` in the worker configuration and `pool: 25` in `database.yaml`. ```ruby workers 6 ``` ```yaml pool: 25 ``` -------------------------------- ### Scale Workers Down Using SIGUSR1 Source: https://github.com/jondot/sneakers/wiki/Auto-scaling Scaling down worker processes involves a two-step signal process. First, update the `sneakers.conf.rb` file to the desired lower worker count. Then, send the `SIGUSR2` signal for configuration reload, followed by the `SIGUSR1` signal for a graceful restart. This allows existing workers to finish their current tasks before shutting down, and the supervisor will then start the reduced number of workers. ```ruby workers 4 ``` ```bash $ kill -SIGUSR2 `cat sneakers.pid` $ kill -SIGUSR1 `cat sneakers.pid` ``` -------------------------------- ### Running Sneakers Programmatically Source: https://github.com/jondot/sneakers/wiki/How-to:-running-a-stand-alone-worker Provides a Ruby script for the worker's binary file (`bin/myworker`) that sets up Sneakers. It configures AMQP connection, logging to STDOUT, and integrates with Statsd for metrics. The script initializes and runs the Sneakers runner with a specified worker class. ```ruby #!/usr/bin/env ruby require 'bundler/setup' root = File.expand_path('../lib', File.dirname(__FILE__)) $: << root require 'myworker' require 'sneakers/runner' require 'logger' require 'statsd-ruby' statsd = Statsd.new(ENV['STATSD_HOST'], 9125) Sneakers.configure(:amqp => ENV['AMQP_URL'], :daemonize => false, :log => STDOUT, :metrics => Sneakers::Metrics::StatsdMetrics.new(statsd)) Sneakers.logger.level = Logger::INFO r = Sneakers::Runner.new([ Myworker ]) r.run ``` -------------------------------- ### Set up Gemfile for Sneakers Source: https://github.com/jondot/sneakers/blob/master/README.md Configure your Gemfile with Sneakers, JSON, and Redis dependencies. ```Ruby source 'https://rubygems.org' gem 'sneakers' gem 'json' gem 'redis' ``` -------------------------------- ### Configure Sneakers with LoggingMetrics Source: https://github.com/jondot/sneakers/wiki/How-To:-Do-Log-Processing Configures Sneakers to use the LoggingMetrics provider for real-time metric visibility. ```ruby # boot.rb require 'sneakers' require 'redis' require 'json' require 'sneakers/metrics/logging_metrics' Sneakers.configure :metrics => Sneakers::Metrics::LoggingMetrics.new # ... rest of code ``` -------------------------------- ### Use Provided Connections in WorkerGroup Source: https://github.com/jondot/sneakers/blob/master/ChangeLog.md Enables the use of custom connection instances within Sneakers worker groups. This allows for more control over connection management in complex setups. ```Ruby worker_group.use_connection(my_custom_connection) ``` -------------------------------- ### Build Docker Container Source: https://github.com/jondot/sneakers/blob/master/README.md Builds a Docker container for the Sneakers project using the default Dockerfile. The image is tagged as 'sneakers_sneakers'. ```bash docker build . -t sneakers_sneakers ``` -------------------------------- ### Run Integration Tests with Docker Compose Source: https://github.com/jondot/sneakers/blob/master/README.md Orchestrates a full integration test environment using Docker Compose. This includes RabbitMQ and Redis dependencies, and runs tests within the Sneakers Docker image. ```bash scripts/local_integration ``` -------------------------------- ### Configure Sneakers with Logging Metrics Source: https://github.com/jondot/sneakers/blob/master/README.md Integrate Sneakers with logging metrics by requiring the logging_metrics provider and configuring Sneakers accordingly. ```Ruby # boot.rb require 'sneakers' require 'redis' require 'json' require 'sneakers/metrics/logging_metrics' Sneakers.configure(metrics: Sneakers::Metrics::LoggingMetrics.new) # ... rest of code ``` -------------------------------- ### Gemfile Configuration for Sneakers Source: https://github.com/jondot/sneakers/wiki/How-to:-running-a-stand-alone-worker Specifies the necessary Ruby gems for a Sneakers worker project, including dependencies for metrics (statsd-ruby), deployment (foreman), and the Sneakers gem itself. Also includes development and testing dependencies. ```ruby # Gemfile source 'https://rubygems.org' gem "statsd-ruby" # using statsd with Sneakers::Metrics gem "foreman" # for an easy deployment story with Upstart gem "rake" gem 'sneakers' group :test, :development do gem "minitest" gem "rr" end ``` -------------------------------- ### Production Dockerfile Usage Source: https://github.com/jondot/sneakers/blob/master/README.md Specifies the use of 'Dockerfile.slim' for production Docker builds to generate a more compact image compared to the standard 'Dockerfile'. ```dockerfile FROM Dockerfile.slim ``` -------------------------------- ### Procfile for Worker Execution Source: https://github.com/jondot/sneakers/wiki/How-to:-running-a-stand-alone-worker Defines the command to run the Sneakers worker using the Procfile convention, typically used by process managers like Foreman. ```ruby # Procfile myworker: bin/myworker ``` -------------------------------- ### Run Sneakers Worker with ActiveJob Wrapper Source: https://github.com/jondot/sneakers/wiki/How-To:-Rails-Background-Jobs-with-ActiveJob Starts the Sneakers worker process, specifically targeting jobs wrapped by the Active Job adapter. This command is executed via Rake. ```bash WORKERS=ActiveJob::QueueAdapters::SneakersAdapter::JobWrapper rake sneakers:run ``` -------------------------------- ### Configure Sneakers with Forking Hooks Source: https://github.com/jondot/sneakers/wiki/Forking Demonstrates how to configure Sneakers to use 'before_fork' and 'after_fork' hooks. These hooks allow you to execute specific Ruby code before a process forks or after a child process has been created, useful for managing resources like database connections. ```ruby Sneakers.configure ... hooks: { before_fork: ... after_fork: ... } ``` ```ruby hooks: { before_fork: lambda do Mongoid.disconnect_clients end, after_fork: lambda do Mongoid::Clients.clients.each do |_name, client| client.close client.reconnect end end } ``` -------------------------------- ### Incorrect ack! Usage Example Source: https://github.com/jondot/sneakers/wiki/Creating-a-Worker Illustrates incorrect patterns for using the `ack!` job control signal within a Sneakers worker's `work` method. The `ack!` call must be the final statement or explicitly returned for the message acknowledgment to be processed correctly by RabbitMQ. ```ruby # DO NOT do it def work(raw_event) Event.create!(JSON.parse(raw_event)) ack! # this is not returned from method logger.info "Good job" end ``` ```ruby # DO NOT do it def work(raw_event) Event.create!(JSON.parse(raw_event)) logger.info "Good job" ensure ack! # this is not returned from method end ``` -------------------------------- ### Configure Global Sneakers Parameters Source: https://github.com/jondot/sneakers/wiki/How-To:-Rails-Background-Jobs-with-ActiveJob Sets up global configuration for Sneakers, allowing customization of connection parameters and other settings. This is typically done in an initializer file. ```ruby require 'sneakers' Sneakers.configure( ) ``` -------------------------------- ### Publish Message to RabbitMQ Source: https://github.com/jondot/sneakers/blob/master/README.md Use the bunny gem to connect to RabbitMQ, create a channel, and publish a JSON message to the 'logs' queue. ```Ruby require 'bunny' conn = Bunny.new conn.start ch = conn.create_channel ch.default_exchange.publish({ type: 'error', message: 'HALP!', error: 'CODE001' }.to_json, routing_key: 'logs') conn.close ``` -------------------------------- ### Basic Sneakers Worker Implementation Source: https://github.com/jondot/sneakers/wiki/How-To:-Do-Log-Processing Defines a simple Sneakers worker named 'Processor' that listens to the 'logs' queue and logs incoming messages. ```ruby # boot.rb require 'sneakers' class Processor include Sneakers::Worker from_queue :logs def work(msg) logger.info msg end end ``` -------------------------------- ### Programmatic Runner Integration Source: https://github.com/jondot/sneakers/wiki/Home This documentation explains how to run a Sneakers runner programmatically, allowing for custom integration into your application's startup or management processes. ```Ruby # Example of running Sneakers programmatically require 'sneakers' # Configure Sneakers globally or per runner instance Sneakers.configure( amqp: "amqp://guest:guest@localhost:5672", workers_path: "./workers" ) # Define your worker class (e.g., in ./workers/my_programmatic_worker.rb) # class MyProgrammaticWorker # include Sneakers::Worker # from_queue :programmatic_queue # def work(message) # puts "Programmatic worker: #{message}" # ack! # end # end # Instantiate the runner with your worker classes # runner = Sneakers::Runner.new([MyProgrammaticWorker]) # Start the runner # runner.run! # Alternatively, to run multiple workers: # runner = Sneakers::Runner.new([Worker1, Worker2, Worker3]) # runner.run! # For more control, you can manage the runner lifecycle: # runner.setup # runner.work! # runner.teardown ``` -------------------------------- ### Global Sneakers Configuration in Rails Initializer Source: https://github.com/jondot/sneakers/wiki/How-To:-Rails-Background-Jobs This code snippet illustrates how to configure global parameters for Sneakers by creating an initializer file in your Rails application. It requires the Sneakers gem and calls the `configure` method with connection details. ```Ruby # config/initializers/sneakers.rb require 'sneakers' Sneakers.configure( ) ``` -------------------------------- ### Configure LoggingMetrics in Sneakers Source: https://github.com/jondot/sneakers/wiki/Metrics This snippet shows how to configure Sneakers to use the LoggingMetrics provider. This is useful for observing metrics as they occur within the application's logs. ```ruby require 'sneakers/metrics/logging_metrics' Sneakers.configure metrics: Sneakers::Metrics::LoggingMetrics.new, other: 'configuration options' ``` -------------------------------- ### QueuePublisher for JSON Publishing Source: https://github.com/jondot/sneakers/wiki/Testing-Your-Worker This module provides a simple interface for publishing messages to queues using JSON formatting. It generates a JSON string from the payload and then uses the Sneakers publish method. ```ruby module QueuePublisher extend self def publish(payload, routing) json = JSON.generate(payload: payload) Sneakers.publish(json, routing) end end ``` -------------------------------- ### Implement Oneshot Handler in Ruby Source: https://github.com/jondot/sneakers/wiki/Message-Handling-Semantics Demonstrates the implementation of the Oneshot handler for message acknowledgment, rejection, and error/timeout handling. It uses the channel object to perform AMQP operations. ```ruby def initialize(channel) @channel = channel end def acknowledge(tag) @channel.acknowledge(tag, false) end def reject(tag, requeue=false) @channel.reject(tag, requeue) end def error(tag, err) reject(tag) end def timeout(tag) reject(tag) end def noop(tag) end ``` -------------------------------- ### Support :bind_arguments on Bind in Sneakers Source: https://github.com/jondot/sneakers/blob/master/ChangeLog.md Introduces the ability to set arguments on a queue when binding to a headers exchange. This enhances flexibility in configuring message routing. ```Ruby Sneakers.configure(: amqp => "amqp://guest:guest@localhost:5672", exchange_options: { name: "my_exchange", type: :headers, arguments: { :bind_arguments => { :key => "value" } } } ) ``` -------------------------------- ### Configure Custom Handler in Sneakers Source: https://github.com/jondot/sneakers/wiki/Message-Handling-Semantics Shows how to globally configure a custom handler class within the Sneakers application. This allows for tailored message processing logic. ```ruby Sneakers.configure(handler: YourHandlerClass ) ``` -------------------------------- ### Configurable Web Scraper Worker in Ruby Source: https://github.com/jondot/sneakers/wiki/How-To:-Scrape-Web-Pages This Ruby snippet shows an advanced Sneakers worker configuration for web scraping. It allows setting the number of threads to 50, prefetch count to 50, and a job timeout of 1 second. This configuration is suitable for handling a higher volume of I/O operations concurrently. ```ruby require 'sneakers' require 'open-uri' require 'nokogiri' require 'sneakers/metrics/logging_metrics' class WebScraper include Sneakers::Worker from_queue :web_pages, :threads => 50, :prefetch => 50, :timeout_job_after => 1 def work(msg) doc = Nokogiri::HTML(open(msg)) page_title = doc.css('title').text worker_trace "Found: #{page_title}" ack! end end ``` -------------------------------- ### Define a Sneakers Worker Source: https://github.com/jondot/sneakers/blob/master/README.md Create a worker class that includes Sneakers::Worker, specifies a queue, and defines the work method to process messages. ```Ruby require 'sneakers' require 'redis' require 'json' $redis = Redis.new class Processor include Sneakers::Worker from_queue :logs def work(msg) err = JSON.parse(msg) if err["type"] == "error" $redis.incr "processor:#{err["error"]}" end ack! end end ``` -------------------------------- ### Run Non-Integration Tests in Docker Source: https://github.com/jondot/sneakers/blob/master/README.md Executes non-integration tests within a Docker container. The container is automatically removed after the tests complete. ```bash docker run --rm sneakers_sneakers:latest ``` -------------------------------- ### WorkerAdditions for JSON Payload Handling Source: https://github.com/jondot/sneakers/wiki/Testing-Your-Worker This module extends Sneakers workers to handle JSON parsing of incoming messages and publishing of JSON-formatted payloads. It includes a `work` method for consuming data and a `publish` method that serializes payloads to JSON before sending. ```ruby module WorkerAdditions def work(message) data = JSON.parse(message, :symbolize_names => true) ActiveRecord::Base.connection_pool.with_connection do consume(data[:payload]) end ack! end def publish(payload, opts) json = JSON.generate(payload: payload) super(json, opts) end end ```