hermes_messenger_of_the_gods 3.0.0.rc5 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 198222807509b3910bc1db6d0bbe5819956401176abd8b3f1d13c7163c95c1dd
4
- data.tar.gz: f476dc6f1ebf9123527890d229d63e1068c1c6487004879550f9dc3a8307643a
3
+ metadata.gz: 33c9ff0aa4e8742ae7b9d157836767f20d8b1a0a2d9c122677ff0e81c920c3f6
4
+ data.tar.gz: aeaeb01b41023f6e5af9b77e5364eddbf60afcfa02b747350c94e4d324d8a0e5
5
5
  SHA512:
6
- metadata.gz: 1ac7755e67b7c37be401031ea1f8e596d3afe1d26719d7d028964835185d3b2f2fa822bbc7c7dec97f5f411f97b1527397d6d9067e5b718a83eed6f511e74337
7
- data.tar.gz: ad8a934c454ab879432ebdf2d7f363fcbfb8bcf31f74354064274bcf761c0eba21dca927fa1d085cb57d5f35a11025bec62093ddf5c1401c2753c16585a75432
6
+ metadata.gz: '06167683706027e262b8f81e467c89d1ea506197a339419b061662a9d972bcd063d4e79f6f21b2f92177837aa1c958c64d7e4b34074c94fdce2669c69db97338'
7
+ data.tar.gz: fcf709e4fa3dec47060cf6fb63cddf0cfb5d1b87e9f9874b0cbdc6a4ddcbd379b0043ee3a9ccc9782cbd06413ac12d9dd2c1eb92a0756d1416be656e9de7f9e0
@@ -4,12 +4,41 @@ require 'aws-sdk-sqs'
4
4
  require 'json'
5
5
  require_relative './base'
6
6
 
7
+ begin
8
+ require 'k8s-ruby'
9
+ rescue LoadError
10
+ STDERR.puts 'k8s-ruby gem not found. Please install it to enable prefential scale-down of workers.'
11
+ end
12
+
7
13
  module HermesMessengerOfTheGods
8
14
  module Endpoints
9
15
  class Sqs < Base
10
16
  VISIBILITY_EXTEND_DURATION = 120
11
17
  VISIBILITY_EXTEND_FREQUENCY = 60
12
18
 
19
+ def self.k8s_client
20
+ return unless defined?(K8s)
21
+
22
+ @k8s_client ||= K8s::Client.in_cluster_config
23
+ end
24
+
25
+ def self.set_deletion_cost(cost)
26
+ # If there is no k8s client or the cost is the same as the last time we set it, we don't need to do anything
27
+ return unless k8s_client || @last_deletion_cost == cost
28
+
29
+ k8s_client.api('v1').resource('pods', namespace: ENV['SYSTEM_NAMESPACE']).merge_patch(ENV['HOSTNAME'], {
30
+ metadata: {
31
+ annotations: {
32
+ "controller.kubernetes.io/pod-deletion-cost" => cost.to_s
33
+ },
34
+ }
35
+ })
36
+
37
+ @last_deletion_cost = cost
38
+ rescue StandardError => e
39
+ STDERR.puts "Error setting deletion cost: #{e.message}"
40
+ end
41
+
13
42
  def initialize(*args)
14
43
  super
15
44
  @message_mux = Monitor.new
@@ -33,6 +62,14 @@ module HermesMessengerOfTheGods
33
62
  @work_start_time_mux.synchronize { @work_start_time = Time.now }
34
63
  end
35
64
 
65
+ def received_work_in_last_check?
66
+ @work_start_time_mux.synchronize { @received_work_in_last_check || false }
67
+ end
68
+
69
+ def received_work_in_last_check=(val)
70
+ @work_start_time_mux.synchronize { @received_work_in_last_check = val }
71
+ end
72
+
36
73
  def inflight_messages
37
74
  @message_mux.synchronize { @inflight_messages ||= [] }
38
75
  end
@@ -61,11 +98,20 @@ module HermesMessengerOfTheGods
61
98
  end
62
99
 
63
100
  def work_off(&blk)
64
- poller.before_request { |_stats| throw :stop_polling if shutting_down? }
101
+ poller.before_request do |_stats|
102
+ throw :stop_polling if shutting_down?
103
+
104
+ self.class.set_deletion_cost(0) unless received_work_in_last_check?
105
+
106
+ self.received_work_in_last_check = false
107
+ end
65
108
 
66
109
  poller.poll(poll_options) do |messages, _stats|
67
110
  self.inflight_messages = messages = Array.wrap(messages)
68
111
 
112
+ self.received_work_in_last_check = true
113
+ self.class.set_deletion_cost(messages.size)
114
+
69
115
  working_messages do
70
116
  completion_results = messages.group_by do |msg|
71
117
  # We return false if we are shutting down so the messages are not deleted.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HermesMessengerOfTheGods
4
- VERSION = '3.0.0.rc5'
4
+ VERSION = '3.0.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hermes_messenger_of_the_gods
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.rc5
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Malinconico
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2023-10-09 00:00:00.000000000 Z
12
+ date: 2023-10-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -250,9 +250,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
250
250
  version: '0'
251
251
  required_rubygems_version: !ruby/object:Gem::Requirement
252
252
  requirements:
253
- - - ">"
253
+ - - ">="
254
254
  - !ruby/object:Gem::Version
255
- version: 1.3.1
255
+ version: '0'
256
256
  requirements: []
257
257
  rubygems_version: 3.3.7
258
258
  signing_key: