jobby 0.1.2 → 0.1.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/bin/jobby CHANGED
@@ -38,7 +38,7 @@ OptionParser.new do |opts|
38
38
  end
39
39
 
40
40
  opts.on("--version", "Show version") do
41
- puts "0.1.2"
41
+ puts "0.1.3"
42
42
  exit
43
43
  end
44
44
 
@@ -69,11 +69,11 @@ OptionParser.new do |opts|
69
69
  options[:max_child_processes] = forked_children.to_i
70
70
  end
71
71
 
72
- opts.on("-u", "--user [USER]", "Run the processes as this user (probably requires superuser priviledges)") do |user|
72
+ opts.on("-u", "--user [USER]", "Run the processes as this user (probably requires superuser privileges)") do |user|
73
73
  options[:user] = user
74
74
  end
75
75
 
76
- opts.on("-g", "--group [GROUP]", "Run the processes as this group (probably requires superuser priviledges)") do |group|
76
+ opts.on("-g", "--group [GROUP]", "Run the processes as this group (probably requires superuser privileges)") do |group|
77
77
  options[:group] = group
78
78
  end
79
79
 
@@ -84,6 +84,10 @@ OptionParser.new do |opts|
84
84
  opts.on("-c", "--command [COMMAND]", "Run this shell code in the forked children") do |command|
85
85
  options[:command] = command
86
86
  end
87
+
88
+ opts.on("-p", "--prerun [FILEPATH]", "Run this Ruby code before forking any children") do |filepath|
89
+ options[:prerun] = filepath
90
+ end
87
91
  end.parse!
88
92
 
89
93
  Jobby::Runner.new(options).run
data/lib/runner.rb CHANGED
@@ -66,7 +66,7 @@ module Jobby
66
66
  exit if @options[:flush] or @options[:wipe]
67
67
  fork do
68
68
  begin
69
- Jobby::Server.new(@options[:socket], @options[:max_child_processes], @options[:log]).run(&get_proc_from_options)
69
+ Jobby::Server.new(@options[:socket], @options[:max_child_processes], @options[:log], @options[:prerun]).run(&get_proc_from_options)
70
70
  rescue Exception => exception
71
71
  return error(exception.message)
72
72
  end
data/lib/server.rb CHANGED
@@ -53,11 +53,12 @@ module Jobby
53
53
  # % pkill -USR1 -f jobby
54
54
  #
55
55
  class Server
56
- def initialize(socket_path, max_forked_processes, log)
56
+ def initialize(socket_path, max_forked_processes, log, prerun = nil)
57
57
  @socket_path = socket_path
58
58
  @max_forked_processes = max_forked_processes.to_i
59
59
  @log = log
60
60
  @queue = Queue.new
61
+ @prerun = prerun
61
62
  end
62
63
 
63
64
  # Starts the server and listens for connections. The specified block is run in
@@ -69,6 +70,9 @@ module Jobby
69
70
  @logger.error "No block given, exiting"
70
71
  terminate
71
72
  end
73
+ if @prerun
74
+ load File.expand_path(@prerun)
75
+ end
72
76
  start_forking_thread(block)
73
77
  loop do
74
78
  client = @socket.accept
@@ -0,0 +1,2 @@
1
+ module Preran
2
+ end
data/spec/server_spec.rb CHANGED
@@ -11,9 +11,9 @@ $0 = "jobby spec"
11
11
 
12
12
  describe Jobby::Server do
13
13
 
14
- def run_server(socket, max_child_processes, log_filepath, &block)
14
+ def run_server(socket, max_child_processes, log_filepath, prerun = nil, &block)
15
15
  @server_pid = fork do
16
- Jobby::Server.new(socket, max_child_processes, log_filepath).run(&block)
16
+ Jobby::Server.new(socket, max_child_processes, log_filepath, prerun).run(&block)
17
17
  end
18
18
  sleep 0.2
19
19
  end
@@ -176,4 +176,19 @@ describe Jobby::Server do
176
176
  lambda { Jobby::Client.new(@socket) { |c| c.send("hello?") } }.should raise_error(Errno::ENOENT)
177
177
  `pgrep -f 'jobby spec'`.strip.should eql("#{Process.pid}")
178
178
  end
179
+
180
+ it "should be able to run a Ruby file before any forking" do
181
+ terminate_server
182
+ run_server(@socket, 1, @log_filepath, "spec/file_for_prerunning.rb") do
183
+ sleep 2
184
+ if defined?(Preran)
185
+ File.open(@child_filepath, "a+") do |file|
186
+ file << "preran OK"
187
+ end
188
+ end
189
+ end
190
+ Jobby::Client.new(@socket) { |c| c.send("hiya") }
191
+ sleep 3
192
+ File.read(@child_filepath).should eql("preran OK")
193
+ end
179
194
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jobby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Somerville
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-07-07 00:00:00 +01:00
12
+ date: 2008-07-08 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -28,6 +28,7 @@ files:
28
28
  - lib/client.rb
29
29
  - spec/server_spec.rb
30
30
  - spec/run_all.rb
31
+ - spec/file_for_prerunning.rb
31
32
  - README
32
33
  has_rdoc: true
33
34
  homepage: http://mark.scottishclimbs.com/