jcnetdev-bj 1.0.33

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,133 @@
1
+ class Bj
2
+ module Util
3
+ module ModuleMethods
4
+ def constant_get const, &block
5
+ begin
6
+ ancestors = const.split(%r/::/)
7
+ parent = Object
8
+ while((child = ancestors.shift))
9
+ klass = parent.const_get child
10
+ parent = klass
11
+ end
12
+ klass
13
+ rescue
14
+ block ? block.call : raise
15
+ end
16
+ end
17
+
18
+ def const_or_env const, &block
19
+ constant_get(const){ ENV[const] || block.call }
20
+ end
21
+
22
+ def spawn cmd, options = {}
23
+ options.to_options!
24
+ logger = options.has_key?(:logger) ? options[:logger] : Bj.logger
25
+ verbose = options.has_key? :verbose
26
+ logger.info{ "cmd <#{ cmd }>" } if logger
27
+ status = systemu cmd, 1=>(stdout=""), 2=>(stderr="")
28
+ logger.info{ "status <#{ status.exitstatus }>" } if logger
29
+ if verbose
30
+ if logger
31
+ if stdout.empty?
32
+ logger.info{ "stdout <>" }
33
+ else
34
+ logger.info{ "stdout <" }
35
+ logger << stdout.strip.gsub(%r/^/, ' ')
36
+ logger << "\n>\n"
37
+ end
38
+ if stderr.empty?
39
+ logger.info{ "stderr <>" }
40
+ else
41
+ logger.info{ "stderr <" }
42
+ logger << stderr.strip.gsub(%r/^/, ' ')
43
+ logger << "\n>\n"
44
+ end
45
+ else
46
+ STDOUT.puts stdout
47
+ STDERR.puts stderr
48
+ end
49
+ end
50
+ status.exitstatus.zero? or raise "#{ cmd.inspect } failed with #{ $?.inspect }"
51
+ [ stdout, stderr ]
52
+ end
53
+
54
+ def start *a
55
+ q = Queue.new
56
+ thread = Thread.new do
57
+ Thread.current.abort_on_exception = true
58
+ systemu(*a){|pid| q << pid}
59
+ end
60
+ pid = q.pop
61
+ thread.singleton_class{ define_method(:pid){ pid } }
62
+ thread
63
+ end
64
+
65
+ def alive pid
66
+ return false unless pid
67
+ pid = Integer pid.to_s
68
+ Process::kill 0, pid
69
+ true
70
+ rescue Errno::ESRCH, Errno::EPERM
71
+ false
72
+ end
73
+ alias_method "alive?", "alive"
74
+
75
+ def which_ruby
76
+ c = ::Config::CONFIG
77
+ ruby = File::join(c['bindir'], c['ruby_install_name']) << c['EXEEXT']
78
+ raise "ruby @ #{ ruby } not executable!?" unless test(?e, ruby)
79
+ ruby
80
+ end
81
+
82
+ def which_rake
83
+ tmp = Tempfile.new Process.pid
84
+ tmp.write "task(:foobar){ puts 42 }"
85
+ tmp.close
86
+ bat = spawn("rake.bat -f #{ tmp.path.inspect } foobar", :logger => false) rescue false
87
+ bat ? "rake.bat" : "rake"
88
+ ensure
89
+ tmp.close! rescue nil
90
+ end
91
+
92
+ def ipc_signals_supported
93
+ @ipc_signals_supported ||=
94
+ IO.popen 'ruby', 'r+' do |ruby|
95
+ pid = ruby.pid
96
+ begin
97
+ Process.kill 'TERM', pid
98
+ true
99
+ rescue Exception
100
+ false
101
+ end
102
+ end
103
+ end
104
+ alias_method "ipc_signals_supported?", "ipc_signals_supported"
105
+
106
+ def find_script basename
107
+ path = ENV["PATH"] || ENV["path"] || Bj.default_path
108
+ raise "no env PATH" unless path
109
+ path = path.split File::PATH_SEPARATOR
110
+ path.unshift File.join(Bj.rails_root, "script")
111
+ path.each do |directory|
112
+ script = File.join directory, basename
113
+ return File.expand_path(script) if(test(?s, script) and test(?r, script))
114
+ end
115
+ raise "no #{ basename } found in #{ path.inspect }"
116
+ end
117
+
118
+ def valid_rails_root root = ".", expected = %w[ config script app ]
119
+ directories = expected.flatten.compact.map{|dir| dir.to_s}
120
+ directories.all?{|dir| test(?d, File.join(root, dir))}
121
+ end
122
+ alias_method "valid_rails_root?", "valid_rails_root"
123
+
124
+ def emsg e
125
+ m = e.message rescue ""
126
+ c = e.class rescue Exception
127
+ b = e.backtrace.join("\n") rescue ""
128
+ "#{ m }(#{ c })\n#{ b }"
129
+ end
130
+ end
131
+ send :extend, ModuleMethods
132
+ end
133
+ end
@@ -0,0 +1 @@
1
+ require 'bj'
@@ -0,0 +1,3 @@
1
+ task :foobar do
2
+ puts 42
3
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jcnetdev-bj
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.33
5
+ platform: ruby
6
+ authors:
7
+ - Ara T. Howard
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-07-06 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "2.1"
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: main
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 2.6.0
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: systemu
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.2.0
41
+ version:
42
+ - !ruby/object:Gem::Dependency
43
+ name: orderedhash
44
+ version_requirement:
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.0.3
50
+ version:
51
+ description: Backgroundjob (Bj) is a brain dead simple zero admin background priority queue for Rails. Bj is robust, platform independent (including windows), and supports internal or external manangement of the background runner process.
52
+ email: ara.t.howard@gmail.com
53
+ executables: []
54
+
55
+ extensions: []
56
+
57
+ extra_rdoc_files:
58
+ - README
59
+ files:
60
+ - bin/bj
61
+ - bj.gemspec
62
+ - HISTORY
63
+ - init.rb
64
+ - install.rb
65
+ - lib/bj/api.rb
66
+ - lib/bj/attributes.rb
67
+ - lib/bj/bj.rb
68
+ - lib/bj/errors.rb
69
+ - lib/bj/joblist.rb
70
+ - lib/bj/logger.rb
71
+ - lib/bj/runner.rb
72
+ - lib/bj/stdext.rb
73
+ - lib/bj/table.rb
74
+ - lib/bj/util.rb
75
+ - lib/bj.rb
76
+ - rails/init.rb
77
+ - rakefile
78
+ - README
79
+ - TODO
80
+ has_rdoc: true
81
+ homepage: http://codeforpeople.com/lib/ruby/bj/
82
+ post_install_message:
83
+ rdoc_options:
84
+ - --main
85
+ - README
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: "0"
93
+ version:
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: "0"
99
+ version:
100
+ requirements: []
101
+
102
+ rubyforge_project:
103
+ rubygems_version: 1.2.0
104
+ signing_key:
105
+ specification_version: 2
106
+ summary: Background Priority Queue
107
+ test_files: []
108
+