pipa-monkeyjob 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
@@ -5,10 +5,10 @@ module Monkey
|
|
5
5
|
def run_local(*args)
|
6
6
|
super(*args) do
|
7
7
|
begin
|
8
|
-
ActiveRecord::Base.dirty_reconnect!
|
8
|
+
::ActiveRecord::Base.dirty_reconnect!
|
9
9
|
yield(*args)
|
10
10
|
ensure
|
11
|
-
ActiveRecord::Base.connection_handler.clear_all_connections!
|
11
|
+
::ActiveRecord::Base.connection_handler.clear_all_connections!
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -17,16 +17,12 @@ module Monkey
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
20
|
+
ActiveRecord::Base
|
21
|
+
|
22
|
+
class ActiveRecord::Base
|
23
|
+
def self.dirty_reconnect!
|
24
|
+
@@connection_handler = ::ActiveRecord::ConnectionAdapters::ConnectionHandler.new
|
25
|
+
establish_connection
|
28
26
|
end
|
29
27
|
end
|
30
28
|
|
31
|
-
::ActiveRecord::Base.extend Monkey::Runner::Fork::Rails::ActiveRecord::BasePatch
|
32
|
-
|
@@ -23,19 +23,22 @@ module Monkey
|
|
23
23
|
raise ArgumentError, 'block must be provided' unless block_given?
|
24
24
|
pid = fork do
|
25
25
|
trap('TERM') do
|
26
|
-
Monkey.logger.warn "Process #{Process.pid} received SIGTERM, will exit!"
|
26
|
+
Monkey.logger.warn "Process #{Process.pid} received SIGTERM, will exit!(2)"
|
27
27
|
exit!(2)
|
28
28
|
end
|
29
|
-
ActiveRecord::Base.spawn_reconnect
|
30
29
|
begin
|
30
|
+
Monkey.logger.debug "Process #{Process.pid} running"
|
31
31
|
yield(*args)
|
32
|
+
Monkey.logger.debug "Process #{Process.pid} will exit!"
|
32
33
|
exit!(0)
|
33
34
|
rescue
|
34
35
|
Monkey.logger.error $!
|
36
|
+
Monkey.logger.error "Process #{Process.pid} failed, will exit!(1)"
|
35
37
|
exit!(1)
|
36
38
|
end
|
37
39
|
end
|
38
40
|
(spid = Process.detach(pid))[:pid] = pid
|
41
|
+
Monkey.logger.debug "Forked #{pid}"
|
39
42
|
spid
|
40
43
|
end
|
41
44
|
|