Class: Newshound::Jobs::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/newshound/jobs/base.rb

Overview

Base class for job source adapters Each adapter is responsible for:

  1. Fetching queue statistics from its specific job backend
  2. Fetching job counts grouped by type
  3. Formatting job data for banner display

Subclasses must implement:

  • #queue_statistics - Returns a hash of queue stats
  • #job_counts_by_type - Returns a hash of job class => counts

Unlike Warnings::Base and Exceptions::Base (which format individual records), #format_for_banner takes no arguments and returns aggregate queue statistics. A default implementation is provided that delegates to #queue_statistics.

Direct Known Subclasses

Que

Instance Method Summary collapse

Instance Method Details

#format_for_bannerHash

Returns data formatted for the banner UI

Returns:

  • (Hash)

    with key :queue_stats containing ready_to_run, scheduled, failing, expired, failed, completed_today



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/newshound/jobs/base.rb', line 40

def format_for_banner
  stats = queue_statistics

  {
    queue_stats: {
      ready_to_run: stats[:ready],
      scheduled: stats[:scheduled],
      failing: stats[:failing],
      # Adapters written before the failing/expired split report only :failed.
      expired: stats.fetch(:expired) { stats[:failed] },
      failed: stats[:failed],
      completed_today: stats[:finished_today]
    }
  }
end

#job_counts_by_typeHash

Returns job counts grouped by job class

Returns:

  • (Hash)

    job_class => { success:, failing:, expired:, failed:, total: }

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/newshound/jobs/base.rb', line 32

def job_counts_by_type
  raise NotImplementedError, "#{self.class} must implement #job_counts_by_type"
end

#queue_statisticsHash

Returns queue-level statistics

Returns:

  • (Hash)

    with keys :ready, :scheduled, :failing, :expired, :failed, :finished_today. :failing counts jobs that errored and will retry, :expired counts jobs that are out of retries. :failed is the union and is deprecated.

Raises:

  • (NotImplementedError)


25
26
27
# File 'lib/newshound/jobs/base.rb', line 25

def queue_statistics
  raise NotImplementedError, "#{self.class} must implement #queue_statistics"
end