Class: PgqWeb::PgqController

Inherits:
ApplicationController show all
Defined in:
app/controllers/pgq_web/pgq_controller.rb

Constant Summary collapse

KEYS_NAMES =
{'lag' => "Lag", 'last_seen' => "Last Seen", 'queue_name' => "Queue Name", 'consumer_name' => "Consumer", 
'status' => "Status", 'pending_events' => "Pending", 'host' => "Db Host", 'db' => "Database", 'errors_count' => "Errors Count",
'actions' => "Actions"}

Instance Method Summary collapse

Instance Method Details

#deleteObject



115
116
117
118
119
120
121
122
123
# File 'app/controllers/pgq_web/pgq_controller.rb', line 115

def delete
  data = @db.pgq_failed_event_delete(params['queue_name'], params['consumer_name'], params['ev_id'].to_i)
  str = (data.to_i == 1) ? params['ev_id'].to_s : '-'
  @res = "deleted event " + str
  
  respond_to do |f|
    f.js {}
  end
end

#delete_allObject



105
106
107
108
# File 'app/controllers/pgq_web/pgq_controller.rb', line 105

def delete_all    
  @db.pgq_mass_delete_failed_events(params['queue_name'], params['consumer_name'], 5_000)
  redirect_to :action => :errors
end

#errorsObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/pgq_web/pgq_controller.rb', line 20

def errors
  @keys = %w(host db queue_name errors_count actions)
  @keys_names = @keys.inject({}){|r, el| r[el] = el; r}
  @keys_names.merge!(KEYS_NAMES)
  
  @info = consumer_info

  @info = @info.map do |row|
    count = row['database'].pgq_failed_event_count(row['queue_name'], row['consumer_name'])
    if count.to_i > 0
      row['errors_count'] = "#{count.to_i}"
      row
    end
  end.compact.sort{|a, b| a['failed_count'] <=> b['failed_count']}
end

#errors_listObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/pgq_web/pgq_controller.rb', line 36

def errors_list
  @queue_name = params['queue_name']
  @consumer_name = params['consumer_name']
  
  params['per_page'] ||= 30
  
  page = (params['page'] || 1).to_i
  per_page = params['per_page'].to_i
  
  offset = 0
  
  @errors_count = @db.pgq_failed_event_count(params['queue_name'], params['consumer_name'])

  @errors  = WillPaginate::Collection.create(page, per_page) do |pager|
    pager.total_entries = @errors_count
      
    offset = pager.total_entries - page * per_page
    
    if offset < 0
      offset = 0
    end

    pager.replace(@db.pgq_failed_event_list(@queue_name, @consumer_name, per_page, offset))
  end
end

#indexObject



12
13
14
15
16
17
18
# File 'app/controllers/pgq_web/pgq_controller.rb', line 12

def index
  @keys = %w(consumer_name queue_name last_seen lag status pending_events)
  @keys_names = @keys.inject({}){|r, el| r[el] = el; r}
  @keys_names.merge!(KEYS_NAMES)
  @info = consumer_info
  @info_groups = @info.group_by{|row| [row['host'], row['db']]}
end

#pending_events_countObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/controllers/pgq_web/pgq_controller.rb', line 88

def pending_events_count
  table, last_event = @db.pgq_last_event_id(params['queue_name'])
  
  res = if last_event
    @last_event = last_event.to_i
    @db.connection.select_value "SELECT count(*) FROM #{table} WHERE ev_id > #{last_event.to_i}"
  else
    '-'
  end

  @res = res
  
  respond_to do |f|
    f.js {}
  end
end

#pending_listObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/controllers/pgq_web/pgq_controller.rb', line 62

def pending_list
  @last_event = params['last_event'].to_i
  @queue_name = params['queue_name']
  table, last_event = @db.pgq_last_event_id(params['queue_name'])
  
  @pending_count = @db.connection.select_one("SELECT count(*) as count FROM #{table} WHERE ev_id > #{(last_event || @last_event).to_i}")['count']
  
  params['per_page'] ||= 30
  
  page = (params['page'] || 1).to_i
  per_page = (params['per_page']).to_i
  
  @pending = WillPaginate::Collection.create(page, per_page) do |pager|
    pager.total_entries = @pending_count
         
    offset = pager.total_entries - page * per_page
                  
    if offset < 0
      offset = 0
    end
    
    data = @db.connection.select_all("SELECT * FROM #{table} WHERE ev_id > #{(last_event || @last_event).to_i} OFFSET #{offset.to_i} LIMIT #{per_page.to_i}")
    pager.replace(data)
  end                                                         
end

#retryObject



125
126
127
128
129
130
131
132
# File 'app/controllers/pgq_web/pgq_controller.rb', line 125

def retry
  data = @db.pgq_failed_event_retry(params['queue_name'], params['consumer_name'], params['ev_id'].to_i)
  @res = "retried event " + data.to_s
  
  respond_to do |f|
    f.js {}
  end
end

#retry_allObject



110
111
112
113
# File 'app/controllers/pgq_web/pgq_controller.rb', line 110

def retry_all
  @db.pgq_mass_retry_failed_events(params['queue_name'], params['consumer_name'], 5_000)
  redirect_to :action => :errors
end