Skip to content

Commit

Permalink
A bit of reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
julik committed Sep 3, 2024
1 parent 23f33f4 commit cb04808
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
14 changes: 6 additions & 8 deletions lib/gouda.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/gouda/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/gouda/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Gouda
VERSION = "0.1.12"
VERSION = "0.1.13"
end
6 changes: 3 additions & 3 deletions test/gouda/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cb04808

Please sign in to comment.