octopusci 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,22 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ def display_help
4
+ puts "Usage: octopusci-tentacles <command>"
5
+ puts " Acceptable Commands:"
6
+ puts " start - Cleanup existing workers and start new worker processes in the background"
7
+ puts " stop - Signals workers to exit when current job is finished"
8
+ puts " restart - Synonym for the 'start' command, just here for convenience"
9
+ puts " help - Display this help"
10
+ puts ""
11
+ puts " Example: octopusci-tentacles start"
12
+ puts ""
13
+ end
14
+
15
+ if !["start", "stop", "restart", "help"].include?(ARGV[0])
16
+ display_help()
17
+ exit 1
18
+ end
19
+
3
20
  $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
4
21
 
5
22
  require 'rubygems'
@@ -13,4 +30,15 @@ if Octopusci::CONFIG.has_key?('stages')
13
30
  Octopusci::StageLocker.load(Octopusci::CONFIG['stages'])
14
31
  end
15
32
 
16
- Octopusci::WorkerLauncher.launch
33
+ case ARGV[0]
34
+ when "start"
35
+ Octopusci::WorkerLauncher.cleanup_existing_workers()
36
+ Octopusci::WorkerLauncher.launch()
37
+ when "restart"
38
+ Octopusci::WorkerLauncher.cleanup_existing_workers()
39
+ Octopusci::WorkerLauncher.launch()
40
+ when "stop"
41
+ Octopusci::WorkerLauncher.cleanup_existing_workers()
42
+ when "help"
43
+ display_help()
44
+ end
@@ -1,3 +1,3 @@
1
1
  module Octopusci
2
- Version = VERSION = '0.0.7'
2
+ Version = VERSION = '0.0.8'
3
3
  end
@@ -3,7 +3,30 @@ require 'octopusci/config'
3
3
 
4
4
  module Octopusci
5
5
  module WorkerLauncher
6
+ def self.cleanup_existing_workers
7
+ exist_worker_pids = get_worker_pids()
8
+ puts "Cleaning up any existing workers... (#{exist_worker_pids.join(',')})"
9
+ exist_worker_pids.each do |pid|
10
+ wait_to_finish_and_exit(pid)
11
+ end
12
+ del_worker_pids
13
+ puts "Finished cleaning up workers"
14
+ end
15
+
6
16
  def self.launch
17
+ puts "Launching new workers..."
18
+
19
+ # We need to disconnect the redis connection because when we fork and
20
+ # each fork gets a copy of the same connection it is a problem and the
21
+ # redis protocol will detect it and throw an exception. This is
22
+ # necessary because each forked instance needs its own redis connection.
23
+ # This only works because Resque.redis manages a singleton an instance
24
+ # variable and if that instance variable isn't set then it reconnects
25
+ # and returns the new connection.
26
+ Resque.redis.quit
27
+
28
+ worker_pids = []
29
+
7
30
  Octopusci::CONFIG['stages'].size.times do
8
31
  cur_pid = Process.fork do
9
32
  queues = ['commit']
@@ -11,8 +34,69 @@ module Octopusci
11
34
  worker.log "Starting worker #{worker}"
12
35
  worker.work(5)
13
36
  end
14
- Process.waitall
37
+
38
+ worker_pids << cur_pid
39
+
40
+ Process.detach(cur_pid)
41
+
42
+ puts "Launched worker with pid (#{cur_pid})"
43
+ end
44
+
45
+ worker_pids.each do |pid|
46
+ push_worker_pid(pid)
47
+ end
48
+
49
+ puts "Finished launching workers"
50
+ end
51
+
52
+ def self.kill(signal_str, pid)
53
+ begin
54
+ Process.kill(signal_str, pid.to_i)
55
+ puts "Sent '#{signal_str}' signal to worker with pid (#{pid})"
56
+ rescue Errno::ESRCH => e
57
+ puts "Failed to send '#{signal_str}' to worker with pid (#{pid}) - #{e.to_s}"
58
+ end
59
+ end
60
+
61
+ def self.wait_to_finish_and_exit(pid)
62
+ kill("QUIT", pid)
63
+ end
64
+
65
+ def self.immediately_kill_child_and_exit(pid)
66
+ kill("TERM", pid)
67
+ end
68
+
69
+ def self.immediately_kill_child(pid)
70
+ kill("USR1", pid)
71
+ end
72
+
73
+ def self.do_not_process_new_jobs(pid)
74
+ kill("USR2", pid)
75
+ end
76
+
77
+ def self.start_to_process_new_jobs_again(pid)
78
+ kill("CONT", pid)
79
+ end
80
+
81
+ def self.push_worker_pid(pid)
82
+ Resque.redis.rpush(pids_list_key, pid)
83
+ end
84
+
85
+ def self.get_worker_pids
86
+ len = Resque.redis.llen(pids_list_key())
87
+ if len > 0
88
+ return Resque.redis.lrange(pids_list_key(), 0, len-1)
89
+ else
90
+ return []
15
91
  end
16
92
  end
93
+
94
+ def self.del_worker_pids
95
+ Resque.redis.del(pids_list_key())
96
+ end
97
+
98
+ def self.pids_list_key
99
+ "octopusci:workerpids"
100
+ end
17
101
  end
18
102
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octopusci
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ date: 2011-09-24 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sinatra
17
- requirement: &70211609598780 !ruby/object:Gem::Requirement
17
+ requirement: &70139320769340 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70211609598780
25
+ version_requirements: *70139320769340
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: json
28
- requirement: &70211609596740 !ruby/object:Gem::Requirement
28
+ requirement: &70139320767300 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70211609596740
36
+ version_requirements: *70139320767300
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: resque
39
- requirement: &70211609595100 !ruby/object:Gem::Requirement
39
+ requirement: &70139320765660 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *70211609595100
47
+ version_requirements: *70139320765660
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: actionmailer
50
- requirement: &70211609592780 !ruby/object:Gem::Requirement
50
+ requirement: &70139320763340 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *70211609592780
58
+ version_requirements: *70139320763340
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: activerecord
61
- requirement: &70211609591620 !ruby/object:Gem::Requirement
61
+ requirement: &70139320762180 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0'
67
67
  type: :runtime
68
68
  prerelease: false
69
- version_requirements: *70211609591620
69
+ version_requirements: *70139320762180
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: mysql
72
- requirement: &70211609589840 !ruby/object:Gem::Requirement
72
+ requirement: &70139320760400 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: '0'
78
78
  type: :runtime
79
79
  prerelease: false
80
- version_requirements: *70211609589840
80
+ version_requirements: *70139320760400
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: multi_json
83
- requirement: &70211609588340 !ruby/object:Gem::Requirement
83
+ requirement: &70139320758900 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ! '>='
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: '0'
89
89
  type: :runtime
90
90
  prerelease: false
91
- version_requirements: *70211609588340
91
+ version_requirements: *70139320758900
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: time-ago-in-words
94
- requirement: &70211609587720 !ruby/object:Gem::Requirement
94
+ requirement: &70139320758280 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ! '>='
@@ -99,10 +99,10 @@ dependencies:
99
99
  version: '0'
100
100
  type: :runtime
101
101
  prerelease: false
102
- version_requirements: *70211609587720
102
+ version_requirements: *70139320758280
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: rake
105
- requirement: &70211609586460 !ruby/object:Gem::Requirement
105
+ requirement: &70139320757020 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
108
  - - ! '>='
@@ -110,10 +110,10 @@ dependencies:
110
110
  version: '0'
111
111
  type: :development
112
112
  prerelease: false
113
- version_requirements: *70211609586460
113
+ version_requirements: *70139320757020
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: rspec
116
- requirement: &70211609577940 !ruby/object:Gem::Requirement
116
+ requirement: &70139320748500 !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements:
119
119
  - - ! '>='
@@ -121,10 +121,10 @@ dependencies:
121
121
  version: '0'
122
122
  type: :development
123
123
  prerelease: false
124
- version_requirements: *70211609577940
124
+ version_requirements: *70139320748500
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rack-test
127
- requirement: &70211609575640 !ruby/object:Gem::Requirement
127
+ requirement: &70139320746200 !ruby/object:Gem::Requirement
128
128
  none: false
129
129
  requirements:
130
130
  - - ! '>='
@@ -132,10 +132,10 @@ dependencies:
132
132
  version: '0'
133
133
  type: :development
134
134
  prerelease: false
135
- version_requirements: *70211609575640
135
+ version_requirements: *70139320746200
136
136
  - !ruby/object:Gem::Dependency
137
137
  name: guard
138
- requirement: &70211609562320 !ruby/object:Gem::Requirement
138
+ requirement: &70139320732880 !ruby/object:Gem::Requirement
139
139
  none: false
140
140
  requirements:
141
141
  - - ! '>='
@@ -143,10 +143,10 @@ dependencies:
143
143
  version: '0'
144
144
  type: :development
145
145
  prerelease: false
146
- version_requirements: *70211609562320
146
+ version_requirements: *70139320732880
147
147
  - !ruby/object:Gem::Dependency
148
148
  name: rb-fsevent
149
- requirement: &70211609560620 !ruby/object:Gem::Requirement
149
+ requirement: &70139320731180 !ruby/object:Gem::Requirement
150
150
  none: false
151
151
  requirements:
152
152
  - - ! '>='
@@ -154,10 +154,10 @@ dependencies:
154
154
  version: '0'
155
155
  type: :development
156
156
  prerelease: false
157
- version_requirements: *70211609560620
157
+ version_requirements: *70139320731180
158
158
  - !ruby/object:Gem::Dependency
159
159
  name: growl
160
- requirement: &70211609557800 !ruby/object:Gem::Requirement
160
+ requirement: &70139320728360 !ruby/object:Gem::Requirement
161
161
  none: false
162
162
  requirements:
163
163
  - - ! '>='
@@ -165,10 +165,10 @@ dependencies:
165
165
  version: '0'
166
166
  type: :development
167
167
  prerelease: false
168
- version_requirements: *70211609557800
168
+ version_requirements: *70139320728360
169
169
  - !ruby/object:Gem::Dependency
170
170
  name: guard-rspec
171
- requirement: &70211609535380 !ruby/object:Gem::Requirement
171
+ requirement: &70139320705940 !ruby/object:Gem::Requirement
172
172
  none: false
173
173
  requirements:
174
174
  - - ! '>='
@@ -176,7 +176,7 @@ dependencies:
176
176
  version: '0'
177
177
  type: :development
178
178
  prerelease: false
179
- version_requirements: *70211609535380
179
+ version_requirements: *70139320705940
180
180
  description: A multi-branch Continous Integration server that integrates with GitHub
181
181
  email:
182
182
  - cyphactor@gmail.com