Skip to content

Commit

Permalink
fix(core): rails 4 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
pold-lev committed May 3, 2017
1 parent c99d826 commit 972b275
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 60 deletions.
5 changes: 4 additions & 1 deletion lib/treasury/fields/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,11 @@ def initialize_statement
end

def start_snapshot
work_connection.select_value <<-SQL
work_connection.execute <<-SQL
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
SQL

work_connection.select_value <<-SQL
SELECT txid_current_snapshot();
SQL
end
Expand Down
2 changes: 1 addition & 1 deletion lib/treasury/pgq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def pgq_get_batch_events(batch_id, conn)
end

def get_batch_events_by_cursor(batch_id, cursor_name, fetch_size, extra_where, conn)
conn.select_all(<<-SQL.squish)
conn.select_all(<<-SQL.squish).to_a
SELECT * FROM pgq.get_batch_cursor(
#{batch_id},
#{connection.quote(cursor_name)},
Expand Down
18 changes: 8 additions & 10 deletions lib/treasury/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,16 @@ def process_exists?(pid)
end
end

module InstanceMethods
def pid
self.class.pid
end
def pid
self.class.pid
end

def process_is_alive?(pid)
self.class.process_is_alive?(pid)
end
def process_is_alive?(pid)
self.class.process_is_alive?(pid)
end

def process_is_dead?(pid)
self.class.process_is_dead?(pid)
end
def process_is_dead?(pid)
self.class.process_is_dead?(pid)
end
end
end
94 changes: 46 additions & 48 deletions lib/treasury/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,64 +37,62 @@ def current_method_name
end
end

module InstanceMethods
def connection
self.class.connection
end
def connection
self.class.connection
end

def quote(value)
self.class.quote(value)
end
def quote(value)
self.class.quote(value)
end

def log_error(exception)
save_error(self.class.log_error(exception))
rescue
end
def log_error(exception)
save_error(self.class.log_error(exception))
rescue
end

def check_terminate
refresh_state
return true unless @process_object.need_terminate?
logger.warn "Принят сигнал на завершение работы"
@process_object.need_terminate = false
@process_object.save!
false
end
def check_terminate
refresh_state
return true unless @process_object.need_terminate?
logger.warn "Принят сигнал на завершение работы"
@process_object.need_terminate = false
@process_object.save!
false
end

def check_state(state)
@process_object.state == state
end
def check_state(state)
@process_object.state == state
end

def set_state(state)
return set_session if check_state(state) && process_is_alive?(@process_object.pid)
@process_object.state = state
set_session
@process_object.save!
logger.info "Установлен статус %s" % [quote(@process_object.state)]
end
def set_state(state)
return set_session if check_state(state) && process_is_alive?(@process_object.pid)
@process_object.state = state
set_session
@process_object.save!
logger.info "Установлен статус %s" % [quote(@process_object.state)]
end

def set_session
@process_object.pid = pid
@process_object.save!
logger.info "Установлен PID %s" % [quote(@process_object.pid)]
end
def set_session
@process_object.pid = pid
@process_object.save!
logger.info "Установлен PID %s" % [quote(@process_object.pid)]
end

def save_error(error_message)
error_message = error_message[1, 4000] unless error_message.nil?
@process_object.last_error = error_message
@process_object.save!
end
def save_error(error_message)
error_message = error_message[1, 4000] unless error_message.nil?
@process_object.last_error = error_message
@process_object.save!
end

def clear_last_error
save_error(nil)
end
def clear_last_error
save_error(nil)
end

def current_method_name
self.class.current_method_name
end
def current_method_name
self.class.current_method_name
end

def refresh_state
@process_object.reload
end
def refresh_state
@process_object.reload
end
end
end

0 comments on commit 972b275

Please sign in to comment.