ntswf 2.0.2 → 2.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.
- data/lib/ntswf/base.rb +7 -2
- data/lib/ntswf/worker.rb +21 -1
- metadata +1 -1
data/lib/ntswf/base.rb
CHANGED
@@ -5,10 +5,15 @@ module Ntswf
|
|
5
5
|
module Base
|
6
6
|
# @param config [Hash] A configuration with the following keys:
|
7
7
|
# @option config [String] :access_key_id AWS credential
|
8
|
-
# @option config [Hash] :activity_task_lists
|
8
|
+
# @option config [Hash] :activity_task_lists
|
9
|
+
# The task list names for activities as hash (see also *:unit*)
|
9
10
|
# @option config [String] :decision_task_list The task list name for decisions
|
10
11
|
# @option config [String] :domain The SWF domain name
|
11
|
-
# @option config [Numeric] :execution_version
|
12
|
+
# @option config [Numeric] :execution_version
|
13
|
+
# Value allowing clients to reject future execution versions
|
14
|
+
# @option config [String] :pidfile
|
15
|
+
# A path receiving the current PID for looping methods. Causes exit, if
|
16
|
+
# overwritten by another process. See {Worker#in_subprocess}
|
12
17
|
# @option config [Numeric] :subprocess_retries (0) see {Worker#in_subprocess}
|
13
18
|
# @option config [String] :secret_access_key AWS credential
|
14
19
|
# @option config [String] :unit This worker/client's activity task list key
|
data/lib/ntswf/worker.rb
CHANGED
@@ -9,9 +9,12 @@ module Ntswf
|
|
9
9
|
|
10
10
|
# Run a method in a separate process.
|
11
11
|
# This will ensure the call lives on if the master process is terminated.
|
12
|
-
# If the *:subprocess_retries* configuration is set {StandardError}s during the
|
12
|
+
# If the *:subprocess_retries* configuration is set, {StandardError}s during the
|
13
13
|
# method call will be retried accordingly.
|
14
|
+
#
|
15
|
+
# Exits the process if the *:pidfile* configuration is set and the PID file has been modified.
|
14
16
|
def in_subprocess(method)
|
17
|
+
raise_on_pidfile_change if @config.pidfile
|
15
18
|
$stdout.sync = true
|
16
19
|
if child = fork
|
17
20
|
srand
|
@@ -34,5 +37,22 @@ module Ntswf
|
|
34
37
|
log("retrying. exception raised: #{e.message}\n #{e.backtrace.join("\n ")}")
|
35
38
|
retry
|
36
39
|
end
|
40
|
+
|
41
|
+
def raise_on_pidfile_change
|
42
|
+
@pid ||= create_pidfile
|
43
|
+
filed_pid = IO.read(@config.pidfile).strip rescue $!.message
|
44
|
+
if filed_pid != Process.pid.to_s
|
45
|
+
notify("I am a worker, and someone changed *my* PID file. I quit!",
|
46
|
+
pid_file_content: filed_pid,
|
47
|
+
pid_file: @config.pidfile,
|
48
|
+
process_pid: Process.pid,
|
49
|
+
)
|
50
|
+
exit
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def create_pidfile
|
55
|
+
IO.write(@config.pidfile, Process.pid)
|
56
|
+
end
|
37
57
|
end
|
38
58
|
end
|