bjj 1.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.
@@ -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
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bjj
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Ara T. Howard (ara.t.howard@noaa.gov)
8
+ - Daniel Hahn (JRuby modifications)
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-12-15 00:00:00 +01:00
14
+ default_executable: bj
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: main
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 2.6.0
25
+ version:
26
+ - !ruby/object:Gem::Dependency
27
+ name: systemu_j
28
+ type: :runtime
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 1.2.0
35
+ version:
36
+ - !ruby/object:Gem::Dependency
37
+ name: orderedhash
38
+ type: :runtime
39
+ version_requirement:
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 0.0.3
45
+ version:
46
+ description: Special version for JRuby compatibility. 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.
47
+ email: hahn@netseven.it
48
+ executables:
49
+ - bj
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - README
54
+ files:
55
+ - .gitignore
56
+ - HISTORY
57
+ - README
58
+ - Rakefile
59
+ - TODO
60
+ - VERSION.yml
61
+ - bin/bj
62
+ - install.rb
63
+ - lib/bj.rb
64
+ - lib/bj/api.rb
65
+ - lib/bj/attributes.rb
66
+ - lib/bj/bj.rb
67
+ - lib/bj/errors.rb
68
+ - lib/bj/joblist.rb
69
+ - lib/bj/logger.rb
70
+ - lib/bj/runner.rb
71
+ - lib/bj/stdext.rb
72
+ - lib/bj/table.rb
73
+ - lib/bj/util.rb
74
+ has_rdoc: true
75
+ homepage: http://codeforpeople.com/lib/ruby/
76
+ licenses: []
77
+
78
+ post_install_message:
79
+ rdoc_options:
80
+ - --charset=UTF-8
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ version:
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: "0"
94
+ version:
95
+ requirements: []
96
+
97
+ rubyforge_project:
98
+ rubygems_version: 1.3.5
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Backgroundjob
102
+ test_files: []
103
+