Class: MatViews::CreateViewJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/mat_views/create_view_job.rb

Overview

ActiveJob that handles creation of PostgreSQL materialised views for a given MatViewDefinition.

The job:

  1. Normalizes the ‘force` argument.

  2. Looks up the target MatViewDefinition.

  3. Starts a MatViewRun row to track lifecycle/timing, with ‘operation: :create`.

  4. Executes Services::CreateView.

  5. Finalizes the run with success/failure, duration, and meta.

Examples:

Enqueue a create job

MatViews::CreateViewJob.perform_later(definition.id, force: true)

Inline run (test/dev)

MatViews::CreateViewJob.new.perform(definition.id, false)

See Also:

Instance Method Summary collapse

Instance Method Details

#perform(mat_view_definition_id, force_arg = nil, row_count_strategy_arg = nil) ⇒ Hash

Perform the create job for the given materialised view definition.

Parameters:

  • mat_view_definition_id (Integer, String)
  • force_arg (Boolean, Hash, nil) (defaults to: nil)

    Optional flag or hash (‘{ force: true }`)

  • row_count_strategy_arg (:Symbol, String) (defaults to: nil)

    One of: ‘:estimated`, `:exact`, `:none` or `nil`.

Returns:

  • (Hash)

    Serialized ServiceResponse#to_h:

    • ‘:status` [Symbol]

    • ‘:error` [String, nil]

    • ‘:duration_ms` [Integer]

    • ‘:meta` [Hash]

Raises:

  • (StandardError)

    Re-raised on unexpected failure after marking the run failed.



59
60
61
62
63
64
65
66
67
# File 'app/jobs/mat_views/create_view_job.rb', line 59

def perform(mat_view_definition_id, force_arg = nil, row_count_strategy_arg = nil)
  definition = MatViews::MatViewDefinition.find(mat_view_definition_id)

  record_run(definition, :create) do
    MatViews::Services::CreateView.new(definition,
                                       force: force?(force_arg),
                                       row_count_strategy: normalize_strategy(row_count_strategy_arg)).call
  end
end