workpile 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in workpile.gemspec
4
+ gemspec
5
+
6
+ gem "fssm"
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/bin/workpile ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "workpile/cli"
data/dev/child.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'workpile'
2
+ cl = Workpile::Child.new
3
+
4
+ puts "#{cl.index}>#{cl.wait_request.inspect}"
5
+
6
+ loop{sleep(1)}
data/dev/parent.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'workpile'
2
+
3
+ sv = Workpile::Parent.new
4
+ sv.spawn_children(3, "ruby -I../lib child.rb 1 2")
5
+
6
+ while s = gets
7
+ case s
8
+ when /exit/
9
+ sv.abort
10
+ exit
11
+ when /kill/
12
+ sv.kill_working_children
13
+ else
14
+ sv.request s
15
+ end
16
+ end
data/doc/activity.asta ADDED
Binary file
data/doc/activity.png ADDED
Binary file
@@ -0,0 +1,78 @@
1
+ require "rubygems"
2
+ require "fssm"
3
+
4
+ require 'workpile'
5
+ class FSSMGuard
6
+ def initialize
7
+ @watch = {}
8
+ end
9
+
10
+ def guard(&proc)
11
+ instance_exec &proc
12
+ _self = self
13
+ Thread.new do
14
+ FSSM.monitor(".") do
15
+ update{|base,relative| _self.event(base,relative); }
16
+ delete{|base,relative| _self.event(base,relative); }
17
+ create{|base,relative| _self.event(base,relative); }
18
+ end
19
+ end
20
+ $stdin.gets
21
+ on_exit
22
+ end
23
+
24
+ def watch(regexp, &block)
25
+ @watch[regexp] = block
26
+ end
27
+
28
+ def event(base, relative)
29
+ @watch.keys.each do |regexp|
30
+ if m = ( relative.match(regexp) )
31
+ invoke @watch[regexp].call(m)
32
+ end
33
+ end
34
+ end
35
+
36
+ def invoke(fname)
37
+ system(fname)
38
+ end
39
+
40
+ def on_exit
41
+ end
42
+ end
43
+
44
+ class RSpecGuard < FSSMGuard
45
+ def initialize
46
+ super
47
+ @parent = Workpile::Parent.new
48
+ @parent.spawn_children(3, "ruby #{File.dirname(__FILE__) + "\\workpile_rspec.rb"}")
49
+ end
50
+
51
+ def invoke(fname)
52
+ @parent.request(fname)
53
+ end
54
+
55
+ def on_exit
56
+ puts "workpile process shutdown..."
57
+ @parent.abort
58
+ end
59
+ end
60
+
61
+ RSpecGuard.new.guard do
62
+ watch(%r{^spec/.+_spec\.rb$})
63
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
64
+ watch('spec/spec_helper.rb') { "spec" }
65
+
66
+ # Rails example
67
+ watch(%r{^spec/.+_spec\.rb$})
68
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
69
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
70
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
71
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
72
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
73
+ watch('spec/spec_helper.rb') { "spec" }
74
+ watch('config/routes.rb') { "spec/routing" }
75
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
76
+ # Capybara request specs
77
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
78
+ end
@@ -0,0 +1,3 @@
1
+ module Workpile
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,62 @@
1
+ $stdout.sync = true
2
+ Thread.abort_on_exception = true
3
+
4
+ puts "booting..."
5
+
6
+ require 'rubygems'
7
+ require 'rspec'
8
+
9
+ require 'workpile'
10
+ cl = Workpile::Child.new
11
+
12
+ class GemfileBox
13
+ class << self
14
+ def source(*arg)
15
+ end
16
+ def gem(name, *hash)
17
+ if hash[0] and hash[0][:require]
18
+ require hash[0][:require]
19
+ else
20
+ require name
21
+ end
22
+ rescue LoadError
23
+ nil
24
+ end
25
+ def group(sym, &block)
26
+ block.call
27
+ end
28
+ def gemspec(*a)
29
+ end
30
+ end
31
+ instance_eval IO.read("./gemfile") if File.exists?("./gemfile")
32
+ end
33
+
34
+ puts "ready"
35
+
36
+ loop do
37
+ str = cl.wait_request
38
+
39
+ args = str.split(" ")
40
+ src = args[-1]
41
+
42
+ if File.exists?(src)
43
+ break
44
+ else
45
+ puts "Spec File Not Find(#{src})"
46
+ end
47
+ end
48
+
49
+ case src
50
+ when ":exit"
51
+ exit
52
+ else
53
+ puts "load #{src}"
54
+ end
55
+
56
+ begin
57
+ RSpec::Core::Runner.disable_autorun!
58
+ RSpec::Core::Runner.run( [src], STDERR, STDOUT)
59
+ rescue Exception
60
+ puts "#{$!}"
61
+ puts $!.backtrace
62
+ end
data/lib/workpile.rb ADDED
@@ -0,0 +1,102 @@
1
+ require 'drb/drb'
2
+ module Workpile
3
+ class Service
4
+ def initialize
5
+ @queue = Queue.new
6
+ @pids = []
7
+ @boot_pids = []
8
+ end
9
+
10
+ def pop
11
+ @queue.pop
12
+ end
13
+
14
+ def push(obj)
15
+ @queue.push obj
16
+ end
17
+
18
+ def add_working_client(pid)
19
+ @pids << pid
20
+ end
21
+
22
+ def remove_working_client(pid)
23
+ @pids -= [pid]
24
+ end
25
+
26
+ def add_boot_client(pid)
27
+ @boot_pids << pid
28
+ end
29
+
30
+ def remove_boot_client(pid)
31
+ @boot_pids -= [pid]
32
+ end
33
+
34
+ def kill_working_children
35
+ return if @pids.empty?
36
+ s1 = @pids.map{|pid| " /PID #{pid} " }
37
+ IO.popen("start /b taskkill /F #{s1}")
38
+ @pids.clear
39
+ end
40
+
41
+ def kill_boot_children
42
+ return if @boot_pids.empty?
43
+ s1 = @boot_pids.map{|pid| " /PID #{pid} " }
44
+ IO.popen("start /b taskkill /F #{s1}")
45
+ @boot_pids.clear
46
+ end
47
+ end
48
+
49
+ class Parent
50
+ def initialize
51
+ @service = Service.new
52
+ DRb.start_service('druby://127.0.0.1:0',@service)
53
+ @threads = []
54
+ end
55
+
56
+ def request(obj)
57
+ @service.push obj
58
+ end
59
+
60
+ def spawn_children(n, cmd)
61
+ n.times.map do |index|
62
+ @threads << Thread.new do
63
+ while !@abort
64
+ system("#{cmd} #{DRb.uri} #{index}")
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ def kill_working_children
71
+ @service.kill_working_children
72
+ end
73
+
74
+ def abort
75
+ @abort = true
76
+ @threads.each do |th|
77
+ if not th.join(5)
78
+ @service.kill_boot_children
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ class Child
85
+ attr_accessor :index
86
+ def initialize(index = ARGV.pop, uri = ARGV.pop)
87
+ @index = index
88
+ @service = DRbObject.new_with_uri(uri)
89
+ @service.add_boot_client(Process.pid)
90
+ end
91
+
92
+ def wait_request
93
+ req = @service.pop
94
+ @service.add_working_client(Process.pid)
95
+ at_exit do
96
+ @service.remove_working_client(Process.pid)
97
+ @service.remove_boot_client(Process.pid)
98
+ end
99
+ req
100
+ end
101
+ end
102
+ end
data/workpile.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "workpile/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "workpile"
7
+ s.version = Workpile::VERSION
8
+ s.authors = ["drvo"]
9
+ s.email = ["drvo.gm@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{pipe manage subprocess}
12
+ s.description = %q{create subprocess by pipe. manage that.}
13
+
14
+ s.rubyforge_project = "workpile"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency "fssm"
22
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: workpile
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
11
+ platform: ruby
12
+ authors:
13
+ - drvo
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-12-05 00:00:00 +09:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: fssm
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: create subprocess by pipe. manage that.
36
+ email:
37
+ - drvo.gm@gmail.com
38
+ executables:
39
+ - workpile
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - .gitignore
46
+ - Gemfile
47
+ - Rakefile
48
+ - bin/workpile
49
+ - dev/child.rb
50
+ - dev/parent.rb
51
+ - doc/activity.asta
52
+ - doc/activity.png
53
+ - lib/workpile.rb
54
+ - lib/workpile/cli.rb
55
+ - lib/workpile/version.rb
56
+ - lib/workpile/workpile_rspec.rb
57
+ - workpile.gemspec
58
+ has_rdoc: true
59
+ homepage: ""
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options: []
64
+
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ requirements: []
86
+
87
+ rubyforge_project: workpile
88
+ rubygems_version: 1.6.2
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: pipe manage subprocess
92
+ test_files: []
93
+