Executors has been DEPRECATED and is no longer actively developed or maintained. This repository exists as a reference only.
Executors is a wrapper for Java's Executor Service classes allowing seamless integration with JRuby on Rails.
Multiple executor services and their associated commands can be instantiated via a configuration file and are then easily accessible from any point within a Rails application.
require "executors/services" Executors::Services.logger = Logger.new(STDOUT) Executors::Services.load_yaml_string YAML.load_file(Rails.root.join("config", "executors.yml"))
You can load a configuration file that is structured similar to database.yml (with development, test and production subsections) by using [Rails.env].
Executors::Services.load_yaml_string YAML.load_file(Rails.root.join("config", "executors.yml"))[Rails.env]
Not providing a logger via Executors::Services.logger will mean failures will be silent.
Example YAML configuration.
- id: scheduler type: scheduled # cached | fixed | scheduled | single | single_scheduled size: 1 # number of threads commands: # optional - command: MyCommand # class name initial: 1 # initial delay delay: 60 # delay units: minutes # days | hours | microseconds | milliseconds | minutes | nanoseconds | seconds - id: pre_processing type: fixed size: 5 - id: processing type: cached
command = MyCommand.new Executors::Services.get(:processing).submit command
When processing across multiple executors, use the returned Future object to track progress.
command_one = MyCommandOne.new future = Executors::Services.get(:pre_processing).submit command_one command_two = MyCommandTwo.new future Executors::Services.get(:processing).submit command_two