Class: Tasker::Functions::FunctionBasedSlowestTasks

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

Overview

Wrapper for the get_slowest_tasks_v01 SQL function

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

Examples:

Basic usage

slowest_tasks = Tasker::Functions::FunctionBasedSlowestTasks.call
slowest_tasks.each { |task| puts "#{task.task_name}: #{task.duration_seconds}s" }

With filters and time period

since_time = 24.hours.ago
filtered_tasks = Tasker::Functions::FunctionBasedSlowestTasks.call(
  since_timestamp: since_time,
  limit_count: 5,
  namespace_filter: 'payments',
  task_name_filter: 'process_payment'
)

Defined Under Namespace

Classes: SlowestTask

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<SlowestTask>

Call the get_slowest_tasks_v01 SQL function

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_tasks.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_tasks_v01($1, $2, $3, $4, $5)'
  binds = [
    since_timestamp,
    limit_count,
    namespace_filter,
    task_name_filter,
    version_filter
  ]

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

  result.map do |row|
    SlowestTask.new(
      task_id: row['task_id'].to_i,
      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,
      step_count: row['step_count'].to_i,
      completed_steps: row['completed_steps'].to_i,
      error_steps: row['error_steps'].to_i,
      created_at: Time.zone.parse(row['created_at'].to_s),
      completed_at: row['completed_at'] ? Time.zone.parse(row['completed_at'].to_s) : nil,
      initiator: row['initiator'],
      source_system: row['source_system']
    )
  end
end