bensheldon/good_job · error · ArgumentError

Must provide a block

Error message

Must provide a block

What it means

Error "Must provide a block" thrown in bensheldon/good_job.

Source

Thrown at app/models/concerns/good_job/advisory_lockable.rb:386

          cte_query = cte_query.limit(select_limit) if select_limit
          cte_type = supports_cte_materialization_specifiers? ? :MATERIALIZED : :""
          composed_cte = Arel::Nodes::As.new(cte_table, Arel::Nodes::UnaryOperation.new(cte_type, cte_query.arel))

          lock_condition = "#{function}(#{advisory_lock_bigint_sql("#{_quoted_table_name_string} || '-' || #{adapter_class.quote_table_name(cte_table.name)}.#{adapter_class.quote_column_name(column)}::text")})"
          query = cte_table.project(cte_table[:id])
                           .with(composed_cte)
                           .where(defined?(Arel::Nodes::BoundSqlLiteral) ? Arel::Nodes::BoundSqlLiteral.new(lock_condition, [], {}) : Arel::Nodes::SqlLiteral.new(lock_condition))

          limit = original_query.arel.ast.limit
          query.limit = limit.value if limit.present?

          unscoped.where(Arel::Nodes::InfixOperation.new("IN", arel_table[primary_key], query)).merge(original_query.only(:order))
        end
      end

      # @deprecated Use {.advisory_lock} with a block instead.
      def with_advisory_lock(**kwargs, &block)
        raise ArgumentError, "Must provide a block" unless block

        advisory_lock(**kwargs, &block)
      end

      # Acquires an advisory lock on this record if it is not already locked by
      # another database session. Be careful to ensure you release the lock when
      # you are done with {#advisory_unlock_key} to release all remaining locks.
      # @param key [String, Symbol] Key to Advisory Lock against
      # @param function [String, Symbol] Postgres Advisory Lock function name to use
      # @return [Boolean] whether the lock was acquired.
      def advisory_lock_key(key, function: advisory_lockable_function, connection: nil)
        query = if function.include? "_try_"
                  <<~SQL.squish
                    SELECT #{function}(#{advisory_lock_bigint_sql('$1::text')}) AS locked
                  SQL
                else
                  <<~SQL.squish
                    SELECT #{function}(#{advisory_lock_bigint_sql('$1::text')})::text AS locked

View on GitHub (pinned to 5fcde48f87)

Solutions

  1. Call the advisory lock method with a block; the lock is held only for the duration of the block.
  2. Pass a block to with_advisory_lock.

Example fix

record.with_advisory_lock do
  # work under the lock
end

When it happens

Trigger: Thrown at app/models/concerns/good_job/advisory_lockable.rb:386 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of bensheldon/good_job@5fcde48f87 (2026-08-23). Data as JSON: /api/errors/2d949b24b1663685. Report an issue: GitHub.