Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Wrapper for Java's Executor framework allowing seamless integration with JRuby
Ruby
tree: e8100e027e

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
test
.gitignore
CHANGELOG.rdoc
Gemfile
LICENSE
README.rdoc
Rakefile
executors.gemspec

README.rdoc

Executors has been DEPRECATED and is no longer actively developed or maintained. This repository exists as a reference only.

Executors

Introduction

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.

Installation

gem "executors"

Initialising

Example initializer.

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.

Configuration

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

Commands

Submitting a command to an executor. A command must implement either the Callable or Runnable Java interfaces.

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
Something went wrong with that request. Please try again.