ntswf 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/ntswf/base.rb +7 -2
  2. data/lib/ntswf/worker.rb +21 -1
  3. metadata +1 -1
@@ -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 The task list names for activities as hash (see also *:unit*)
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 Value allowing clients to reject future execution versions
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
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ntswf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: