Sha256: f71940e2b7a7838148d8fa67da14c3b23a96fb2f2b24afe5d1022bffe6dcdbfd

Contents?: true

Size: 1.62 KB

Versions: 17

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true
module GoodJob
  class JobsFilter < BaseFilter
    def states
      query = filtered_query(params.except(:state))
      {
        'scheduled' =>  query.scheduled.count,
        'retried' => query.retried.count,
        'queued' => query.queued.count,
        'running' => query.running.count,
        'succeeded' => query.succeeded.count,
        'discarded' => query.discarded.count,
      }
    end

    def filtered_query(filter_params = params)
      query = base_query

      query = query.job_class(filter_params[:job_class]) if filter_params[:job_class].present?
      query = query.where(queue_name: filter_params[:queue_name]) if filter_params[:queue_name].present?
      query = query.search_text(filter_params[:query]) if filter_params[:query].present?
      query = query.where(cron_key: filter_params[:cron_key]) if filter_params[:cron_key].present?

      if filter_params[:state]
        case filter_params[:state]
        when 'discarded'
          query = query.discarded
        when 'succeeded'
          query = query.succeeded
        when 'retried'
          query = query.retried
        when 'scheduled'
          query = query.scheduled
        when 'running'
          query = query.running.select("#{GoodJob::Job.table_name}.*", 'pg_locks.locktype')
        when 'queued'
          query = query.queued
        end
      end

      query
    end

    def filtered_count
      filtered_query.unscope(:select).count
    end

    private

    def query_for_records
      filtered_query.includes(:executions).includes_advisory_locks
    end

    def default_base_query
      GoodJob::Job.all
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
good_job-3.12.8 app/filters/good_job/jobs_filter.rb
good_job-3.12.7 app/filters/good_job/jobs_filter.rb
good_job-3.12.6 app/filters/good_job/jobs_filter.rb
good_job-3.12.5 app/filters/good_job/jobs_filter.rb
good_job-3.12.4 app/filters/good_job/jobs_filter.rb
good_job-3.12.3 app/filters/good_job/jobs_filter.rb
good_job-3.12.2 app/filters/good_job/jobs_filter.rb
good_job-3.12.1 app/filters/good_job/jobs_filter.rb
good_job-3.12.0 app/filters/good_job/jobs_filter.rb
good_job-3.11.1 app/filters/good_job/jobs_filter.rb
good_job-3.11.0 app/filters/good_job/jobs_filter.rb
good_job-3.10.1 app/filters/good_job/jobs_filter.rb
good_job-3.10.0 app/filters/good_job/jobs_filter.rb
good_job-3.9.0 app/filters/good_job/jobs_filter.rb
good_job-3.8.0 app/filters/good_job/jobs_filter.rb
good_job-3.7.4 app/filters/good_job/jobs_filter.rb
good_job-3.7.3 app/filters/good_job/jobs_filter.rb