pipemaster 0.5.0 → 0.5.1
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/CHANGELOG +6 -0
- data/README.rdoc +44 -0
- data/bin/pipe +6 -1
- data/lib/pipemaster/configurator.rb +1 -1
- data/lib/pipemaster/server.rb +12 -2
- data/pipemaster.gemspec +1 -1
- data/test/unit/test_server.rb +10 -0
- metadata +3 -3
data/CHANGELOG
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
0.5.1 (2010-03-01)
|
2
|
+
* Added: Ping command:
|
3
|
+
$ pipe ping
|
4
|
+
0.5.1
|
5
|
+
* Added: List command, returns list of all available commands.
|
6
|
+
|
1
7
|
0.5.0 (2010-03-01)
|
2
8
|
This release adds background processes. The Pipefile can specify multiple
|
3
9
|
background activities. Pipemaster starts each activity by forking a new child
|
data/README.rdoc
CHANGED
@@ -46,6 +46,50 @@ Step 3: For a new shell, execute a command:
|
|
46
46
|
Stand upside down!
|
47
47
|
|
48
48
|
|
49
|
+
== Pipemaster, Resque and Rails
|
50
|
+
|
51
|
+
This example uses Resque to queue and process tasks asynchronously, where the
|
52
|
+
tasks are part of a larger Rails application (e.g. using ActiveRecord models,
|
53
|
+
ActiveMailer).
|
54
|
+
|
55
|
+
This Pipefile loads the Rails application once during setup. It starts one
|
56
|
+
Resque worker than polls for new jobs every 5 seconds.
|
57
|
+
|
58
|
+
#!/usr/bin/env ruby -S pipemaster
|
59
|
+
user "nobody"
|
60
|
+
|
61
|
+
require "syslog_logger"
|
62
|
+
syslog = SyslogLogger.new("pipemaster")
|
63
|
+
class << syslog ; def close ; end ; end
|
64
|
+
logger syslog
|
65
|
+
|
66
|
+
setup do
|
67
|
+
# Load RAILS. Diz will take a while.
|
68
|
+
require File.dirname(__FILE__) + '/config/environment'
|
69
|
+
ActiveRecord::Base.connection.disconnect!
|
70
|
+
end
|
71
|
+
after_fork do |server, worker|
|
72
|
+
ActiveRecord::Base.establish_connection
|
73
|
+
end
|
74
|
+
|
75
|
+
# Resque
|
76
|
+
background :resque do
|
77
|
+
resque = Resque::Worker.new("*")
|
78
|
+
resque.verbose = true
|
79
|
+
trap(:QUIT) { resque.shutdown } # graceful
|
80
|
+
resque.work(5)
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
== Tips && tricks
|
85
|
+
|
86
|
+
Add this at the top of your Pipefile for Ruby syntax highlighting:
|
87
|
+
|
88
|
+
|
89
|
+
#!ruby -S pipemaster
|
90
|
+
|
91
|
+
|
92
|
+
|
49
93
|
== License
|
50
94
|
|
51
95
|
Pipemaster is copyright of Assaf Arkin. It is heavily based on the awesome
|
data/bin/pipe
CHANGED
@@ -9,7 +9,12 @@ retcode = nil
|
|
9
9
|
tty = false
|
10
10
|
|
11
11
|
opts = OptionParser.new("", 24, ' ') do |opts|
|
12
|
-
opts.banner = "Usage: #{File.basename($0)} [options] command [args]\n"
|
12
|
+
opts.banner = "Usage: #{File.basename($0)} [options] command [args]\n" \
|
13
|
+
"\nCommon commands:\n" \
|
14
|
+
" list List all commands available on server (one name per line)\n" \
|
15
|
+
" ping Pings server (returns version number)\n"
|
16
|
+
|
17
|
+
opts.separator "\nOptions:"
|
13
18
|
|
14
19
|
opts.on("-t", "--tty", "read input from terminal (default: false)") do |t|
|
15
20
|
tty = t ? true : false
|
data/lib/pipemaster/server.rb
CHANGED
@@ -387,6 +387,11 @@ module Pipemaster
|
|
387
387
|
proc_name 'master (old)'
|
388
388
|
end
|
389
389
|
|
390
|
+
DEFAULT_COMMANDS = {
|
391
|
+
:list => lambda { $stdout << (DEFAULT_COMMANDS.keys | commands.keys).sort.join("\n") },
|
392
|
+
:ping => lambda { $stdout << VERSION }
|
393
|
+
}
|
394
|
+
|
390
395
|
def process_request(socket, worker)
|
391
396
|
trap(:QUIT) { exit }
|
392
397
|
[:TERM, :INT].each { |sig| trap(sig) { exit! } }
|
@@ -406,8 +411,13 @@ module Pipemaster
|
|
406
411
|
logger.info "#{Process.pid} #{name} #{args.join(' ')}"
|
407
412
|
|
408
413
|
ARGV.replace args
|
409
|
-
command = commands[name.to_sym]
|
410
|
-
|
414
|
+
if command = commands[name.to_sym]
|
415
|
+
command.call *args
|
416
|
+
elsif command = DEFAULT_COMMANDS[name.to_sym]
|
417
|
+
instance_eval &command
|
418
|
+
else
|
419
|
+
raise ArgumentError, "No command #{name}"
|
420
|
+
end
|
411
421
|
logger.info "#{Process.pid} exit"
|
412
422
|
socket.write 0.chr
|
413
423
|
rescue SystemExit => ex
|
data/pipemaster.gemspec
CHANGED
data/test/unit/test_server.rb
CHANGED
@@ -148,4 +148,14 @@ class ServerTest < Test::Unit::TestCase
|
|
148
148
|
sync.close!
|
149
149
|
end
|
150
150
|
|
151
|
+
def test_ping_command
|
152
|
+
start
|
153
|
+
assert_equal Pipemaster::VERSION, hit("127.0.0.1:#@port", :ping).last
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_list_command
|
157
|
+
start :commands => { :foo => lambda { } }
|
158
|
+
assert_equal "foo\nlist\nping", hit("127.0.0.1:#@port", :list).last
|
159
|
+
end
|
160
|
+
|
151
161
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 5
|
8
|
-
-
|
9
|
-
version: 0.5.
|
8
|
+
- 1
|
9
|
+
version: 0.5.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Assaf Arkin
|
@@ -56,7 +56,7 @@ licenses: []
|
|
56
56
|
post_install_message: To get started run pipemaster --help
|
57
57
|
rdoc_options:
|
58
58
|
- --title
|
59
|
-
- Pipemaster 0.5.
|
59
|
+
- Pipemaster 0.5.1
|
60
60
|
- --main
|
61
61
|
- README.rdoc
|
62
62
|
- --webcvs
|