elf 0.0.1.alpha
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +11 -0
- data/elf.gemspec +17 -0
- data/lib/elf.rb +9 -0
- data/lib/elf/child.rb +31 -0
- data/lib/elf/fork.rb +12 -0
- data/lib/elf/process.rb +16 -0
- data/lib/elf/sync.rb +5 -0
- data/lib/elf/version.rb +3 -0
- data/spec/elf/process_spec.rb +24 -0
- data/spec/spec_helper.rb +3 -0
- metadata +62 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 fl00r
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Elf
|
2
|
+
|
3
|
+
Elves are creatures to manage background processes.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'elf'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install elf
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Elves are creatures to manage background processes.
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/elf.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/elf/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Petr Yanovich"]
|
6
|
+
gem.email = ["fl00r@yandex.ru"]
|
7
|
+
gem.description = %q{Elves are creatures to manage background processes}
|
8
|
+
gem.summary = %q{Elves are creatures to manage background processes}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "elf"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Elf::VERSION
|
17
|
+
end
|
data/lib/elf.rb
ADDED
data/lib/elf/child.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Elf
|
2
|
+
class Child
|
3
|
+
def initialize(cmd)
|
4
|
+
@cmd = cmd
|
5
|
+
fire
|
6
|
+
end
|
7
|
+
|
8
|
+
def success=(&blk)
|
9
|
+
@success = blk
|
10
|
+
success if @status.exitstatus == 0
|
11
|
+
end
|
12
|
+
|
13
|
+
def success
|
14
|
+
puts "Success: #{@cmd}"
|
15
|
+
@success.call if @success
|
16
|
+
end
|
17
|
+
|
18
|
+
def error
|
19
|
+
puts "Failed: #{@cmd}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def fire
|
23
|
+
fork_pid = ::Process.fork do
|
24
|
+
puts "Fired: #{@cmd}"
|
25
|
+
exec @cmd
|
26
|
+
end
|
27
|
+
pid, @status = ::Process.waitpid2(fork_pid)
|
28
|
+
@status.exitstatus == 0 ? success : error
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/elf/fork.rb
ADDED
data/lib/elf/process.rb
ADDED
data/lib/elf/sync.rb
ADDED
data/lib/elf/version.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Elf::Process do
|
5
|
+
it "should run 3 parallel processes" do
|
6
|
+
start = Time.now
|
7
|
+
Elf::Process.new do |elf|
|
8
|
+
elf.fork("sleep 1")
|
9
|
+
elf.fork("sleep 2")
|
10
|
+
elf.fork("sleep 2")
|
11
|
+
end
|
12
|
+
(Time.now-start).to_i.must_equal(2)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should run 3 sequenced processes" do
|
16
|
+
start = Time.now
|
17
|
+
Elf::Process.new do |elf|
|
18
|
+
elf.sync("sleep 1")
|
19
|
+
elf.sync("sleep 2")
|
20
|
+
elf.sync("sleep 3")
|
21
|
+
end
|
22
|
+
(Time.now-start).to_i.must_equal(6)
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: elf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.alpha
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Petr Yanovich
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-18 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: Elves are creatures to manage background processes
|
15
|
+
email:
|
16
|
+
- fl00r@yandex.ru
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- elf.gemspec
|
27
|
+
- lib/elf.rb
|
28
|
+
- lib/elf/child.rb
|
29
|
+
- lib/elf/fork.rb
|
30
|
+
- lib/elf/process.rb
|
31
|
+
- lib/elf/sync.rb
|
32
|
+
- lib/elf/version.rb
|
33
|
+
- spec/elf/process_spec.rb
|
34
|
+
- spec/spec_helper.rb
|
35
|
+
homepage: ''
|
36
|
+
licenses: []
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>'
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.3.1
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.8.15
|
56
|
+
signing_key:
|
57
|
+
specification_version: 3
|
58
|
+
summary: Elves are creatures to manage background processes
|
59
|
+
test_files:
|
60
|
+
- spec/elf/process_spec.rb
|
61
|
+
- spec/spec_helper.rb
|
62
|
+
has_rdoc:
|