From cb04808660acec1732e49b7616d4778dfd50557f Mon Sep 17 00:00:00 2001 From: Julik Tarkhanov Date: Tue, 3 Sep 2024 19:31:05 +0200 Subject: [PATCH] A bit of reformatting --- lib/gouda.rb | 14 ++++++-------- lib/gouda/adapter.rb | 2 +- lib/gouda/version.rb | 2 +- test/gouda/test_helper.rb | 6 +++--- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/gouda.rb b/lib/gouda.rb index d989280..26ebcec 100644 --- a/lib/gouda.rb +++ b/lib/gouda.rb @@ -64,10 +64,8 @@ def self.configure def self.logger # By default, return a logger that sends data nowhere. The `Rails.logger` method # only becomes available later in the Rails lifecycle. - @fallback_gouda_logger ||= begin - ActiveSupport::Logger.new($stdout).tap do |logger| - logger.level = Logger::WARN - end + @fallback_gouda_logger ||= ActiveSupport::Logger.new($stdout).tap do |logger| + logger.level = Logger::WARN end # We want the Rails-configured loggers to take precedence over ours, since Gouda @@ -81,22 +79,22 @@ def self.logger Rails.try(:logger) || ActiveJob::Base.try(:logger) || @fallback_gouda_logger end - def self.suppressing_sql_logs(&blk) + def self.suppressing_sql_logs(&) # This is used for frequently-called methods that poll the DB. If logging is done at a low level (DEBUG) # those methods print a lot of SQL into the logs, on every poll. While that is useful if # you collect SQL queries from the logs, in most cases - especially if this is used # in a side-thread inside Puma - the output might be quite annoying. So silence the # logger when we poll, but just to INFO. Omitting DEBUG-level messages gets rid of the SQL. if Gouda::Workload.logger - Gouda::Workload.logger.silence(Logger::INFO, &blk) + Gouda::Workload.logger.silence(Logger::INFO, &) else # In tests (and at earlier stages of the Rails boot cycle) the global ActiveRecord logger may be nil yield end end - def self.instrument(channel, options, &block) - ActiveSupport::Notifications.instrument("#{channel}.gouda", options, &block) + def self.instrument(channel, options, &) + ActiveSupport::Notifications.instrument("#{channel}.gouda", options, &) end def self.create_tables(active_record_schema) diff --git a/lib/gouda/adapter.rb b/lib/gouda/adapter.rb index 39a15ca..6a3aa7c 100644 --- a/lib/gouda/adapter.rb +++ b/lib/gouda/adapter.rb @@ -57,7 +57,7 @@ def enqueue_all(active_jobs) # We can't tell Postgres to ignore conflicts on _both_ the scheduler key and the enqueue concurrency key but not on # the ID - it is either "all indexes" or "just one", but never "this index and that index". MERGE https://www.postgresql.org/docs/current/sql-merge.html # is in theory capable of solving this but let's not complicate things all to hastily, the hour is getting late - scheduler_key = active_job.try(:executions) == 0 ? active_job.scheduler_key : nil # only enforce scheduler key on first workload + scheduler_key = (active_job.try(:executions) == 0) ? active_job.scheduler_key : nil # only enforce scheduler key on first workload { active_job_id: active_job.job_id, # Multiple jobs can have the same ID due to retries, job-iteration etc. scheduled_at: active_job.scheduled_at || t_now, diff --git a/lib/gouda/version.rb b/lib/gouda/version.rb index 228be7e..7b659de 100644 --- a/lib/gouda/version.rb +++ b/lib/gouda/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Gouda - VERSION = "0.1.12" + VERSION = "0.1.13" end diff --git a/test/gouda/test_helper.rb b/test/gouda/test_helper.rb index 4f4d65e..6259b28 100644 --- a/test/gouda/test_helper.rb +++ b/test/gouda/test_helper.rb @@ -58,14 +58,14 @@ def truncate_test_tables def subscribed_notification_for(notification) payload = nil - subscription = ActiveSupport::Notifications.subscribe notification do |name, start, finish, id, _payload| - payload = _payload + subscription = ActiveSupport::Notifications.subscribe notification do |name, start, finish, id, local_payload| + payload = local_payload end yield ActiveSupport::Notifications.unsubscribe(subscription) - return payload + payload end end