Class: Karafka::Web::Ui::Controllers::JobsController

Inherits:
BaseController show all
Defined in:
lib/karafka/web/ui/controllers/jobs_controller.rb

Overview

Active jobs (work) reporting controller

Direct Known Subclasses

Pro::Ui::Controllers::JobsController

Constant Summary

Constants inherited from BaseController

BaseController::Models

Instance Method Summary collapse

Methods inherited from BaseController

#initialize

Constructor Details

This class inherits a constructor from Karafka::Web::Ui::Controllers::BaseController

Instance Method Details

#pendingObject

Lists pending jobs



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/karafka/web/ui/controllers/jobs_controller.rb', line 43

def pending
  current_state = Models::ConsumersState.current!
  processes = Models::Processes.active(current_state)

  @jobs_counters = count_jobs_types(processes)

  # Aggregate jobs and inject the process info into them for better reporting
  jobs_total = processes.flat_map do |process|
    process.jobs.pending.map do |job|
      job.to_h[:process] = process
      job
    end
  end

  @jobs, last_page = Paginators::Arrays.call(
    refine(jobs_total),
    @params.current_page
  )

  paginate(@params.current_page, !last_page)

  render
end

#runningObject

Lists running jobs



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/karafka/web/ui/controllers/jobs_controller.rb', line 18

def running
  current_state = Models::ConsumersState.current!
  processes = Models::Processes.active(current_state)

  @jobs_counters = count_jobs_types(processes)

  # Aggregate jobs and inject the process info into them for better reporting
  jobs_total = processes.flat_map do |process|
    process.jobs.running.map do |job|
      job.to_h[:process] = process
      job
    end
  end

  @jobs, last_page = Paginators::Arrays.call(
    refine(jobs_total),
    @params.current_page
  )

  paginate(@params.current_page, !last_page)

  render
end