Sha256: 01f897296903f08ffc0ca46d5cb3532a620194cf8783ba9dc28465caa494e5c7

Contents?: true

Size: 1.76 KB

Versions: 33

Compression:

Stored size: 1.76 KB

Contents

# frozen_string_literal: true

module GoodJob
  class BaseFilter
    DEFAULT_LIMIT = 25
    EMPTY = '[none]'

    attr_accessor :params, :base_query

    def initialize(params, base_query = nil)
      @params = params
      @base_query = base_query || default_base_query
    end

    def records
      after_scheduled_at = params[:after_scheduled_at].present? ? Time.zone.parse(params[:after_scheduled_at]) : nil

      query_for_records.display_all(
        after_scheduled_at: after_scheduled_at,
        after_id: params[:after_id]
      ).limit(params.fetch(:limit, DEFAULT_LIMIT))
    end

    def last
      @_last ||= records.last
    end

    def queues
      base_query.group(:queue_name).count
                .sort_by { |name, _count| name.to_s || EMPTY }
                .to_h
    end

    def job_classes
      filtered_query(params.slice(:queue_name)).unscope(:select)
                                               .group(GoodJob::BaseExecution.params_job_class).count
                                               .sort_by { |name, _count| name.to_s }
                                               .to_h
    end

    def states
      raise NotImplementedError
    end

    def to_params(override = {})
      {
        job_class: params[:job_class],
        limit: params[:limit],
        queue_name: params[:queue_name],
        query: params[:query],
        state: params[:state],
        cron_key: params[:cron_key],
      }.merge(override).delete_if { |_, v| v.blank? }
    end

    def filtered_query(filtered_params = params)
      raise NotImplementedError
    end

    def filtered_count
      filtered_query.count
    end

    private

    def query_for_records
      raise NotImplementedError
    end

    def default_base_query
      raise NotImplementedError
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
good_job-3.26.2 app/filters/good_job/base_filter.rb
good_job-3.26.1 app/filters/good_job/base_filter.rb
good_job-3.26.0 app/filters/good_job/base_filter.rb
good_job-3.25.0 app/filters/good_job/base_filter.rb
good_job-3.24.0 app/filters/good_job/base_filter.rb
good_job-3.23.0 app/filters/good_job/base_filter.rb
good_job-3.22.0 app/filters/good_job/base_filter.rb
good_job-3.21.5 app/filters/good_job/base_filter.rb
good_job-3.21.4 app/filters/good_job/base_filter.rb
good_job-3.21.3 app/filters/good_job/base_filter.rb
good_job-3.21.2 app/filters/good_job/base_filter.rb
good_job-3.21.1 app/filters/good_job/base_filter.rb
good_job-3.21.0 app/filters/good_job/base_filter.rb
good_job-3.20.0 app/filters/good_job/base_filter.rb
good_job-3.19.4 app/filters/good_job/base_filter.rb
good_job-3.19.3 app/filters/good_job/base_filter.rb
good_job-3.19.2 app/filters/good_job/base_filter.rb
good_job-3.19.1 app/filters/good_job/base_filter.rb
good_job-3.19.0 app/filters/good_job/base_filter.rb
good_job-3.18.3 app/filters/good_job/base_filter.rb