Class: MatViews::MatViewRun

Inherits:
ApplicationRecord show all
Defined in:
app/models/mat_views/mat_view_run.rb

Overview

ActiveRecord model that tracks the lifecycle of runs for materialised views.

Each record corresponds to a single attempt to mutate a materialised view from a MatViewDefinition, storing its status, timing, and any associated error or metadata.

This model provides an auditable history of view provisioning across environments, useful for telemetry, dashboards, and debugging.

Examples:

Query recent successful runs

MatViews::MatViewRun.status_success.order(created_at: :desc).limit(10)

Check if a definition has any failed runs

definition.mat_view_runs.status_failed.any?

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MatViewsI18n

hint_for, human_enum_name, human_enum_options, human_name, placeholder_for

Instance Attribute Details

#operationSymbol (readonly)

Returns One of:

  • :create - initial creation of the materialised view

  • :refresh - refreshing an existing view

  • :drop - dropping the materialised view.

Returns:

  • One of:

    • :create - initial creation of the materialised view

    • :refresh - refreshing an existing view

    • :drop - dropping the materialised view



65
66
67
68
69
# File 'app/models/mat_views/mat_view_run.rb', line 65

enum :operation, {
  create: 0,
  refresh: 1,
  drop: 2
}, prefix: :operation

#statusObject (readonly)

Validations

Ensures that a status is always present.



52
53
54
55
56
# File 'app/models/mat_views/mat_view_run.rb', line 52

enum :status, {
  running: 0,
  success: 1,
  failed: 2
}, prefix: :status

Instance Method Details

#create_runsActiveRecord::Relation<MatViews::MatViewRun>

Scope create runs All runs with ‘operation: :create`.

Returns:



81
# File 'app/models/mat_views/mat_view_run.rb', line 81

scope :create_runs, -> { where(operation: :create) }

#drop_runsActiveRecord::Relation<MatViews::MatViewRun>

Scope drop runs All runs with ‘operation: :drop`.

Returns:



93
# File 'app/models/mat_views/mat_view_run.rb', line 93

scope :drop_runs,    -> { where(operation: :drop) }

#mat_view_definitionMatViews::MatViewDefinition

The definition this run belongs to.

Returns:



41
# File 'app/models/mat_views/mat_view_run.rb', line 41

belongs_to :mat_view_definition, class_name: 'MatViews::MatViewDefinition'

#refresh_runsActiveRecord::Relation<MatViews::MatViewRun>

Scope refresh runs All runs with ‘operation: :refresh`.

Returns:



87
# File 'app/models/mat_views/mat_view_run.rb', line 87

scope :refresh_runs, -> { where(operation: :refresh) }

#row_count_afterInteger?

row count after the operation, if applicable

Returns:



103
104
105
# File 'app/models/mat_views/mat_view_run.rb', line 103

def row_count_after
  meta.dig('response', 'row_count_after')
end

#row_count_beforeInteger?

row count before the operation, if applicable

Returns:



97
98
99
# File 'app/models/mat_views/mat_view_run.rb', line 97

def row_count_before
  meta.dig('response', 'row_count_before')
end