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, failed, completed_today



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/newshound/jobs/base.rb', line 36

def format_for_banner
  stats = queue_statistics

  {
    queue_stats: {
      ready_to_run: stats[:ready],
      scheduled: stats[:scheduled],
      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:, failed:, total: }

Raises:

  • (NotImplementedError)


29
30
31
# File 'lib/newshound/jobs/base.rb', line 29

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, :failed, :finished_today

Raises:

  • (NotImplementedError)


22
23
24
# File 'lib/newshound/jobs/base.rb', line 22

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