diff --git a/.rubocop.yml b/.rubocop.yml index 2aea13231..1690ed69f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,8 @@ inherit_from: .rubocop_todo.yml require: + - rubocop-performance + - rubocop-rails - rubocop-rspec inherit_mode: @@ -41,6 +43,12 @@ Metrics: Naming/MemoizedInstanceVariableName: EnforcedStyleForLeadingUnderscores: required +Rails/RakeEnvironment: + Enabled: false + +Rails/ApplicationRecord: + Enabled: false + RSpec/AnyInstance: Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index eea1d0106..46657425d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,29 +1,7 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2020-07-13 18:57:43 UTC using RuboCop version 0.88.0. +# on 2020-07-16 00:15:42 UTC using RuboCop version 0.88.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowAliasSyntax, AllowedMethods. -# AllowedMethods: alias_method, public, protected, private -Layout/EmptyLinesAroundAttributeAccessor: - Exclude: - - 'lib/good_job/lockable.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions. -# SupportedStyles: assign_to_condition, assign_inside_condition -Style/ConditionalAssignment: - Exclude: - - 'bin/lint' - -# Offense count: 2 -# Cop supports --auto-correct. -Style/RedundantRegexpEscape: - Exclude: - - 'spec/support/sql_helper.rb' diff --git a/Gemfile.lock b/Gemfile.lock index dbb219bf7..e1de5a523 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -187,6 +187,12 @@ GEM unicode-display_width (>= 1.4.0, < 2.0) rubocop-ast (0.1.0) parser (>= 2.7.0.1) + rubocop-performance (1.7.0) + rubocop (>= 0.82.0) + rubocop-rails (2.6.0) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 0.82.0) rubocop-rspec (1.42.0) rubocop (>= 0.87.0) ruby-progressbar (1.10.1) @@ -223,6 +229,8 @@ DEPENDENCIES pry rspec-rails rubocop + rubocop-performance + rubocop-rails rubocop-rspec BUNDLED WITH diff --git a/good_job.gemspec b/good_job.gemspec index 07eac76bc..76fa5e167 100644 --- a/good_job.gemspec +++ b/good_job.gemspec @@ -50,5 +50,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency "pry" spec.add_development_dependency "rspec-rails" spec.add_development_dependency "rubocop" + spec.add_development_dependency "rubocop-performance" + spec.add_development_dependency "rubocop-rails" spec.add_development_dependency "rubocop-rspec" end diff --git a/lib/good_job/adapter.rb b/lib/good_job/adapter.rb index 511207ef0..c6fcf87ed 100644 --- a/lib/good_job/adapter.rb +++ b/lib/good_job/adapter.rb @@ -11,7 +11,7 @@ def enqueue(active_job) def enqueue_at(active_job, timestamp) good_job = GoodJob::Job.enqueue( active_job, - scheduled_at: timestamp ? Time.at(timestamp) : nil, + scheduled_at: timestamp ? Time.zone.at(timestamp) : nil, create_with_advisory_lock: inline? ) diff --git a/lib/good_job/lockable.rb b/lib/good_job/lockable.rb index 80d1f7a7f..78918751e 100644 --- a/lib/good_job/lockable.rb +++ b/lib/good_job/lockable.rb @@ -37,14 +37,17 @@ module Lockable scope :owns_advisory_locked, -> { joins_advisory_locks.where('"pg_locks"."pid" = pg_backend_pid()') } attr_accessor :create_with_advisory_lock + after_create -> { advisory_lock }, if: :create_with_advisory_lock end class_methods do - def with_advisory_lock(&block) + def with_advisory_lock + raise ArgumentError, "Must provide a block" unless block_given? + records = advisory_lock.to_a begin - block.call(records) + yield(records) ensure records.each(&:advisory_unlock) end @@ -73,6 +76,8 @@ def advisory_lock! end def with_advisory_lock + raise ArgumentError, "Must provide a block" unless block_given? + advisory_lock! yield ensure diff --git a/spec/support/sql_helper.rb b/spec/support/sql_helper.rb index 21e87b7ba..ef83558c5 100644 --- a/spec/support/sql_helper.rb +++ b/spec/support/sql_helper.rb @@ -1,6 +1,6 @@ module SqlHelper def normalize_sql(sql) - sql.gsub(/\s/, ' ').gsub(/([\(\)])/, ' \1 ').squish + sql.gsub(/\s/, ' ').gsub(/([()])/, ' \1 ').squish end end