hermes_messenger_of_the_gods 3.0.0.rc5 → 3.0.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66cf9c906ee1778e68e8064e13f77c5157284335c7c1f25bb1cf9328b151a1a0
|
4
|
+
data.tar.gz: 55c3008d04eb24472e3c574938140d7db78e68fa8960acc1f5198dc331ffe0d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08844c25373078afe15fca74c7aa7129c46708c62c58865527617de9bf63ef972ab26ae92a14f62363764be2678a924a611be26432216c674190d26340c07cae'
|
7
|
+
data.tar.gz: 2dd3a36e8091eec825c3ae2ddc2843e3b2658cd192c8e1773b0429868a69cb6c969f0c9aa2011670dc9503ee4b6320a62871b2663b319eef2901329a07ca637e
|
data/.github/workflows/test.yml
CHANGED
@@ -7,16 +7,16 @@ jobs:
|
|
7
7
|
strategy:
|
8
8
|
fail-fast: false
|
9
9
|
matrix:
|
10
|
-
rubyVersion: ["2.7.8", "3.0.4", "3.1.2", "3.2.2"]
|
10
|
+
rubyVersion: ["2.7.8", "3.0.4", "3.1.2", "3.2.2", "3.3.7", "3.4.1"]
|
11
11
|
runs-on: ubuntu-latest
|
12
12
|
steps:
|
13
13
|
- name: Install SSH Key
|
14
|
-
uses: webfactory/ssh-agent@v0.
|
14
|
+
uses: webfactory/ssh-agent@v0.9.0
|
15
15
|
with:
|
16
16
|
ssh-private-key: ${{ secrets.GH_ACTIONS_SSH_PRIVATE_KEY }}
|
17
17
|
|
18
18
|
- name: Pull
|
19
|
-
uses: actions/checkout@
|
19
|
+
uses: actions/checkout@v4
|
20
20
|
with:
|
21
21
|
path: ${{ github.workspace }}/src/github.com/${{ github.repository }}
|
22
22
|
- uses: ruby/setup-ruby@v1
|
@@ -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,21 @@ module HermesMessengerOfTheGods
|
|
61
98
|
end
|
62
99
|
|
63
100
|
def work_off(&blk)
|
64
|
-
poller.before_request
|
101
|
+
poller.before_request do |_stats|
|
102
|
+
throw :stop_polling if shutting_down?
|
103
|
+
end
|
104
|
+
|
105
|
+
poller.after_empty_receive do |_stats|
|
106
|
+
self.received_work_in_last_check = false
|
107
|
+
self.class.set_deletion_cost(0)
|
108
|
+
end
|
65
109
|
|
66
110
|
poller.poll(poll_options) do |messages, _stats|
|
67
111
|
self.inflight_messages = messages = Array.wrap(messages)
|
68
112
|
|
113
|
+
self.received_work_in_last_check = true
|
114
|
+
self.class.set_deletion_cost(messages.size)
|
115
|
+
|
69
116
|
working_messages do
|
70
117
|
completion_results = messages.group_by do |msg|
|
71
118
|
# We return false if we are shutting down so the messages are not deleted.
|
@@ -131,17 +178,6 @@ module HermesMessengerOfTheGods
|
|
131
178
|
queue.reload.data
|
132
179
|
end
|
133
180
|
|
134
|
-
def has_pending_work?
|
135
|
-
data = queue_data.attributes
|
136
|
-
|
137
|
-
approximate_pending_messages = data['ApproximateNumberOfMessages'].to_i -
|
138
|
-
data['ApproximateNumberOfMessagesNotVisible'].to_i -
|
139
|
-
data['ApproximateNumberOfMessagesDelayed'].to_i
|
140
|
-
|
141
|
-
# Just in case the math is off
|
142
|
-
approximate_pending_messages.positive?
|
143
|
-
end
|
144
|
-
|
145
181
|
def to_transmit_payload(message, raw_message, dispatch_options = {})
|
146
182
|
send_opts = fetch_option(:send_options, raw_message) || {}
|
147
183
|
|
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.
|
4
|
+
version: 3.0.1
|
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:
|
12
|
+
date: 2025-02-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -250,11 +250,11 @@ 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:
|
255
|
+
version: '0'
|
256
256
|
requirements: []
|
257
|
-
rubygems_version: 3.3.
|
257
|
+
rubygems_version: 3.3.12
|
258
258
|
signing_key:
|
259
259
|
specification_version: 4
|
260
260
|
summary: Create and receive messages like a god!
|