Class: ViewKpisTimeOnTask

Inherits:
ApplicationViewRecord show all
Defined in:
app/models/view_kpis_time_on_task.rb

Overview

== Schema Information

Table name: view_kpis_time_on_tasks
Database name: primary

id :bigint
activities :bigint
business_day :integer
call_block :bigint
credits_value :float
date :date
day_off :float
department :string(30)
emails :bigint
employee_name :string(255)
inbounds :decimal(, )
looms :bigint
missed :decimal(, )
outbounds :decimal(, )
sms :decimal(, )
talk_time :decimal(, )
time_avbl :float
employee_id :integer

Indexes

index_view_kpis_time_on_tasks_on_date (date)
index_view_kpis_time_on_tasks_on_department (department)
index_view_kpis_time_on_tasks_on_employee_id (employee_id)
index_view_kpis_time_on_tasks_on_id (id) UNIQUE

Class Method Summary collapse

Methods inherited from ApplicationViewRecord

create, create!, #readonly?

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Class Method Details

.refresh(concurrently: true, timeout: '15min', retries: 1) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/view_kpis_time_on_task.rb', line 33

def self.refresh(concurrently: true, timeout: '15min', retries: 1)
  connection = ActiveRecord::Base.connection
  original_timeout = connection.select_value('SHOW statement_timeout')
  begin
    connection.execute("SET statement_timeout = '#{timeout}'")
    Scenic.database.refresh_materialized_view(table_name, concurrently: concurrently, cascade: false)
  rescue ActiveRecord::QueryCanceled, ActiveRecord::StatementInvalid => e
    raise unless e.message =~ /(statement timeout|QueryCanceled)/i && retries.positive?

    connection.execute("SET statement_timeout = '0'")
    Scenic.database.refresh_materialized_view(table_name, concurrently: false, cascade: false)
  ensure
    connection.execute("SET statement_timeout = '#{original_timeout}'") if original_timeout
  end
end