Class: Tasker::Functions::FunctionBasedSlowestSteps

Inherits:
FunctionWrapper show all
Defined in:
lib/tasker/functions/function_based_slowest_steps.rb

Overview

Wrapper for the get_slowest_steps_v01 SQL function

This function returns the slowest workflow steps within a specified time period with duration metrics and optional filtering by namespace, task name, and version.

Examples:

Basic usage

slowest_steps = Tasker::Functions::FunctionBasedSlowestSteps.call
slowest_steps.each { |step| puts "#{step.step_name}: #{step.duration_seconds}s" }

With filters and time period

since_time = 24.hours.ago
filtered_steps = Tasker::Functions::FunctionBasedSlowestSteps.call(
  since_timestamp: since_time,
  limit_count: 15,
  namespace_filter: 'inventory',
  task_name_filter: 'update_stock'
)

Defined Under Namespace

Classes: SlowestStep

Class Method Summary collapse

Methods inherited from FunctionWrapper

connection, convert_array_bind, from_sql_function, #readonly?, single_from_sql_function

Class Method Details

.call(since_timestamp: nil, limit_count: 10, namespace_filter: nil, task_name_filter: nil, version_filter: nil) ⇒ Array<SlowestStep>

Call the get_slowest_steps_v01 SQL function

Parameters:

  • since_timestamp (Time, nil) (defaults to: nil)

    Start time for analysis (defaults to 24 hours ago in SQL)

  • limit_count (Integer) (defaults to: 10)

    Maximum number of results to return (default: 10)

  • namespace_filter (String, nil) (defaults to: nil)

    Filter by namespace name

  • task_name_filter (String, nil) (defaults to: nil)

    Filter by task name

  • version_filter (String, nil) (defaults to: nil)

    Filter by task version

Returns:

  • (Array<SlowestStep>)

    Array of slowest step results

Raises:

  • (ActiveRecord::StatementInvalid)

    If the SQL function fails



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/tasker/functions/function_based_slowest_steps.rb', line 51

def self.call(since_timestamp: nil, limit_count: 10, namespace_filter: nil, task_name_filter: nil,
              version_filter: nil)
  # Build SQL with proper parameter binding
  sql = 'SELECT * FROM get_slowest_steps_v01($1, $2, $3, $4, $5)'
  binds = [
    since_timestamp,
    limit_count,
    namespace_filter,
    task_name_filter,
    version_filter
  ]

  result = connection.select_all(sql, 'SlowestSteps Load', binds)

  result.map do |row|
    SlowestStep.new(
      workflow_step_id: row['workflow_step_id'].to_i,
      task_id: row['task_id'].to_i,
      step_name: row['step_name'].to_s,
      task_name: row['task_name'].to_s,
      namespace_name: row['namespace_name'].to_s,
      version: row['version'].to_s,
      duration_seconds: row['duration_seconds'].to_f,
      attempts: row['attempts'].to_i,
      created_at: Time.zone.parse(row['created_at'].to_s),
      completed_at: Time.zone.parse(row['completed_at'].to_s),
      retryable: ['t', true].include?(row['retryable']),
      step_status: row['step_status'].to_s
    )
  end
end