Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lsegal/mob_spawner
Manages and spawns worker threads to run arbitrary shell commands.
https://github.com/lsegal/mob_spawner
Last synced: about 2 months ago
JSON representation
Manages and spawns worker threads to run arbitrary shell commands.
- Host: GitHub
- URL: https://github.com/lsegal/mob_spawner
- Owner: lsegal
- Created: 2012-05-10T00:32:12.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2012-05-10T00:35:18.000Z (over 12 years ago)
- Last Synced: 2024-05-02T05:33:32.123Z (8 months ago)
- Language: Ruby
- Size: 93.8 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MobSpawner
MobSpawner manages worker threads that can run arbitrary commands and report
results. Unlike distributed queues, MobSpawner is self-contained and perfect
for small batch scripts that need to run multiple independent jobs.Documentation is on [rubydoc.org](http://rubydoc.org/gems/mob_spawner/frames).
## Usage
The simplest usage of MobSpawner is:
```ruby
commands = ["rvm install 1.8.6", "rvm install 1.9.2", "rvm install rbx"]
MobSpawner.new(commands).run
```The above will attempt to run the 3 commands concurrently across the default of
3 worker threads. By default commands do not report output; to get command
output, use callbacks discussed in the next section.For more information on how to initialize a spawner, see the {MobSpawner}
documentation.## Callbacks
In addition to simply running worker threads, you can also receive reports
about each worker's execution results using callbacks. To setup a spawner
with callbacks, use {MobSpawner#before_worker} and {MobSpawner#after_worker}:```ruby
spawner = MobSpawner.new("command1", "command2", "command3")
spawner.before_worker do |data|
puts "Worker #{data[:worker]} about to run #{data[:command].command}"
end
spawner.after_worker do |data|
puts "Worker #{data[:worker]} exited with status #{data[:status]}"
puts "Output:"
puts data[:output]
end
spawner.run
```## License & Copyright
MobSpawner is licensed under the MIT license, © 2012 Loren Segal