gouda 0.1.11 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/gouda/version.rb +1 -1
- data/lib/gouda/worker.rb +8 -6
- data/lib/gouda/workload.rb +3 -3
- data/lib/gouda.rb +14 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b26bf19a2b7e37c30fe63354512873c56dc8784b97acf7b3f56bebc9358db71
|
4
|
+
data.tar.gz: cdeee22468899bfd3bcf8ff6914e1b8ff67a9a23f12c1613df51cce8c7b18393
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59c31a696c8e64ba06af1f8b5eedaed7d9aec0dbc76130e6797bdd76badedf37f82a6a0c582686483b855211ed157ee25096689deb347cda44e4af896cf7b5dc
|
7
|
+
data.tar.gz: 8ed39bae53908ebfd1d6f48ad3fb99e0eef6c2cd922a9df4bc42e3a3e8059dfc8e996d240bc593cb5087025ae29d634c5f021997db67d9c63131bedac422abf2
|
data/CHANGELOG.md
CHANGED
@@ -52,3 +52,7 @@
|
|
52
52
|
## [0.1.11] - 2024-07-03
|
53
53
|
|
54
54
|
- Fix: make sure the Gouda logger config does not get used during Rails initialization
|
55
|
+
|
56
|
+
## [0.1.12] - 2024-07-03
|
57
|
+
|
58
|
+
- When doing polling, suppress DEBUG-level messages. This will stop Gouda spamming the logs with SQL in dev/test environments.
|
data/lib/gouda/version.rb
CHANGED
data/lib/gouda/worker.rb
CHANGED
@@ -83,12 +83,13 @@ module Gouda
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def call
|
86
|
-
# return false unless Rails.application # Rails is still booting and there is no application defined
|
87
|
-
|
88
86
|
Gouda.config.app_executor.wrap do
|
89
|
-
Gouda::Workload.waiting_to_start(queue_constraint: @queue_constraint).none?
|
87
|
+
Gouda.suppressing_sql_logs { Gouda::Workload.waiting_to_start(queue_constraint: @queue_constraint).none? }
|
90
88
|
end
|
91
|
-
rescue
|
89
|
+
rescue
|
90
|
+
# It is possible that in this scenario we do not have a database set up yet, for example,
|
91
|
+
# or we are unable to connect to the DB for whatever reason. In that case we should
|
92
|
+
# return `false` so that the worker can poll again later.
|
92
93
|
false
|
93
94
|
end
|
94
95
|
end
|
@@ -158,13 +159,14 @@ module Gouda
|
|
158
159
|
# a stale timestamp can indicate to us that the job was orphaned and is marked as "executing"
|
159
160
|
# even though the worker it was running on has failed for whatever reason.
|
160
161
|
# Later on we can figure out what to do with those jobs (re-enqueue them or toss them)
|
161
|
-
Gouda
|
162
|
+
Gouda.suppressing_sql_logs do # these updates will also be very frequent with long-running jobs
|
163
|
+
Gouda::Workload.where(id: executing_workload_ids.to_a, state: "executing").update_all(executing_on: worker_id, last_execution_heartbeat_at: Time.now.utc)
|
164
|
+
end
|
162
165
|
|
163
166
|
# Find jobs which just hung and clean them up (mark them as "finished" and enqueue replacement workloads if possible)
|
164
167
|
Gouda::Workload.reap_zombie_workloads
|
165
168
|
rescue => e
|
166
169
|
Gouda.instrument(:exception, {exception: e})
|
167
|
-
|
168
170
|
warn "Uncaught exception during housekeeping (#{e.class} - #{e}"
|
169
171
|
end
|
170
172
|
|
data/lib/gouda/workload.rb
CHANGED
@@ -115,9 +115,9 @@ class Gouda::Workload < ActiveRecord::Base
|
|
115
115
|
payload[:retried_checkouts_due_to_concurrent_exec] = 0
|
116
116
|
uncached do # Necessary because we SELECT with a clock_timestamp() which otherwise gets cached by ActiveRecord query cache
|
117
117
|
transaction do
|
118
|
-
jobs.first
|
119
|
-
|
120
|
-
|
118
|
+
job = Gouda.suppressing_sql_logs { jobs.first } # Silence SQL output as this gets called very frequently
|
119
|
+
job&.update!(state: "executing", executing_on: executing_on, last_execution_heartbeat_at: Time.now.utc, execution_started_at: Time.now.utc)
|
120
|
+
job
|
121
121
|
rescue ActiveRecord::RecordNotUnique
|
122
122
|
# It can happen that due to a race the `execution_concurrency_key NOT IN` does not capture
|
123
123
|
# a job which _just_ entered the "executing" state, apparently after we do our SELECT. This will happen regardless
|
data/lib/gouda.rb
CHANGED
@@ -81,6 +81,20 @@ module Gouda
|
|
81
81
|
Rails.try(:logger) || ActiveJob::Base.try(:logger) || @fallback_gouda_logger
|
82
82
|
end
|
83
83
|
|
84
|
+
def self.suppressing_sql_logs(&blk)
|
85
|
+
# This is used for frequently-called methods that poll the DB. If logging is done at a low level (DEBUG)
|
86
|
+
# those methods print a lot of SQL into the logs, on every poll. While that is useful if
|
87
|
+
# you collect SQL queries from the logs, in most cases - especially if this is used
|
88
|
+
# in a side-thread inside Puma - the output might be quite annoying. So silence the
|
89
|
+
# logger when we poll, but just to INFO. Omitting DEBUG-level messages gets rid of the SQL.
|
90
|
+
if Gouda::Workload.logger
|
91
|
+
Gouda::Workload.logger.silence(Logger::INFO, &blk)
|
92
|
+
else
|
93
|
+
# In tests (and at earlier stages of the Rails boot cycle) the global ActiveRecord logger may be nil
|
94
|
+
yield
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
84
98
|
def self.instrument(channel, options, &block)
|
85
99
|
ActiveSupport::Notifications.instrument("#{channel}.gouda", options, &block)
|
86
100
|
end
|