Method: Que::Connection#execute_prepared

Defined in:
lib/que/connection.rb

#execute_prepared(command, params = nil) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/que/connection.rb', line 81

def execute_prepared(command, params = nil)
  Que.assert(Symbol, command)

  if !Que.use_prepared_statements || in_transaction?
    return execute(command, params)
  end

  name = "que_#{command}"

  begin
    unless @prepared_statements.include?(command)
      wrapped_connection.prepare(name, SQL[command])
      @prepared_statements.add(command)
      prepared_just_now = true
    end

    convert_result(
      wrapped_connection.exec_prepared(name, params)
    )
  rescue ::PG::InvalidSqlStatementName => error
    # Reconnections on ActiveRecord can cause the same connection
    # objects to refer to new backends, so recover as well as we can.

    unless prepared_just_now
      Que.log level: :warn, event: :reprepare_statement, command: command
      @prepared_statements.delete(command)
      retry
    end

    raise error
  end
end