herdst_worker 0.2.16 → 0.2.18

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c3bcca0fea942c15752e9a0c7f56f1b0d9a333d9fbe0fcef1cd4b722a0333f72
4
- data.tar.gz: b9868c69103c6b4947b66fe801775c824a848ba0d4cb9ee8284b01593e593996
3
+ metadata.gz: 1cb8f2fe78959dcc72ddb5262d5f775f7e2c8894e4cea3079df5574bc9afa469
4
+ data.tar.gz: 26a30f925cd508910027e86449fc2ed0832dd64232c94f1992b0743a6f108046
5
5
  SHA512:
6
- metadata.gz: e891b196b8418014c671b15fe48498ad7785820ea9dc99c3d1b1ca2a5ab693b822cd006f017b1c6221e747ca4b08eec163be7bc00644327024d3972509ca5302
7
- data.tar.gz: 055ead61ea81ac0025d3e539ae69633031b3fd09b288476eb5f82d6be2eeca504c4d9af8ac81c1d6a51dd5bd01c717f35475844a1ca7d14f567fb10c99049136
6
+ metadata.gz: 72a91bfab0fd4e3c19a6c98eb5c1cbca69c0d07950165145ec15d9c877593f8a497d7c21b931d4ad356141edafe0908556612da24e574352289d38f6fcc9449c
7
+ data.tar.gz: 013a1ef632e3f4fb751399e86fb2004bef44bd84d3fcc17a22a11919f4ba986c2428ee8c48ed38e5c4de7d9fd427de9bc7cd29276e2c487fd69aa02469c3360b
@@ -69,13 +69,23 @@ module HerdstWorker
69
69
 
70
70
 
71
71
  def stop(exit_code = 0)
72
- Concurrent::ScheduledTask.execute(5) do
73
- self.logger.queue.warn "Application exiting (#{exit_code})"
72
+ self.logger.warn "Application exiting (#{exit_code})"
74
73
 
75
- exit(exit_code)
76
- end
74
+ Kernel.exit(exit_code)
77
75
  end
78
76
 
77
+
78
+ def force_stop(delay = 1)
79
+ self.logger.warn "Application force stopping in #{delay} seconds."
80
+ process_id = "#{$$}"
81
+
82
+ Concurrent::ScheduledTask.execute(delay) do
83
+ self.logger.warn "Application force stopping."
84
+
85
+ system("kill -9 #{process_id}")
86
+ end
87
+ end
88
+
79
89
 
80
90
  def config_for(name)
81
91
  self.config.config_for(name)
@@ -9,7 +9,7 @@ module HerdstWorker
9
9
 
10
10
 
11
11
  attr_accessor :app, :enabled, :queue_url, :queue_wait_time, :poller
12
- attr_accessor :start_time, :restart_time, :run_time
12
+ attr_accessor :start_time, :restart_time, :run_time, :force_stop_delay
13
13
  attr_accessor :processor_status, :job_count, :max_jobs
14
14
  attr_accessor :attempt_threshold, :visibility_timeout, :ignored_notifications
15
15
 
@@ -30,6 +30,7 @@ module HerdstWorker
30
30
 
31
31
  # Set the start time
32
32
  self.run_time = (3600 * 4) + (rand * 600).floor # Four hours + bit more (< 10 minutes)
33
+ self.force_stop_delay = 600 # 10 minutes
33
34
  self.reset_time
34
35
 
35
36
  # Start the processor as working
@@ -48,6 +49,10 @@ module HerdstWorker
48
49
  self.poller.poll(:wait_time_seconds => self.queue_wait_time, :skip_delete => false) do |msg|
49
50
  process_message(msg)
50
51
  end
52
+
53
+ if self.processor_status == "stopped"
54
+ self.app.stop(0)
55
+ end
51
56
  else
52
57
  raise "Cannot start a queue which is not enabled"
53
58
  end
@@ -117,32 +122,34 @@ module HerdstWorker
117
122
  current_time = Time.now.utc.to_i
118
123
  if (self.processor_status == "working") && (current_time >= self.restart_time)
119
124
  runtime = current_time - self.start_time
120
- self.app.logger.queue.warn "Stopping after #{runtime} seconds of work"
121
- set_status "stopping"
122
-
123
- # On finishing wait for jobs to complete and then set status
124
- # to idle
125
+ self.app.logger.queue.warn "Preparing to stop after #{runtime} seconds of work"
126
+ self.app.force_stop(self.force_stop_delay)
127
+
128
+ set_status "stopping"
129
+
130
+ # On finishing wait for jobs to complete and then set status to idle
125
131
  elsif self.processor_status == "finishing"
126
132
  if self.job_count == 0
127
133
  self.app.logger.queue.warn "Setting processor status to idle"
128
134
  set_status "idle"
129
135
  end
130
136
 
137
+ end
138
+
131
139
  # On stopping wait for jobs to complete and then set status
132
140
  # to stopped. Once stopped the polling will terminate.
133
- elsif self.processor_status == "stopping"
141
+ if self.processor_status == "stopping"
134
142
  if self.job_count == 0
135
143
  self.app.logger.queue.warn "Setting processor status to stopped"
136
144
  set_status "stopped"
137
145
  end
138
-
139
146
  end
140
147
 
148
+ # Once stopped exit the application
141
149
  if self.processor_status == "stopped"
142
150
  self.app.logger.queue.warn "Stopping polling, Service requested to stop"
143
- self.app.stop(1)
144
-
145
- raise :stop_polling
151
+
152
+ throw :stop_polling
146
153
  end
147
154
  end
148
155
 
@@ -1,3 +1,3 @@
1
1
  module HerdstWorker
2
- VERSION = '0.2.16'
2
+ VERSION = '0.2.18'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: herdst_worker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.16
4
+ version: 0.2.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Herd.St
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-01-13 00:00:00.000000000 Z
11
+ date: 2026-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport