Skip to content

Commit

Permalink
Merge pull request #99 from isqad/master
Browse files Browse the repository at this point in the history
Merge branch bz2021-november-1 into master and release v1.11.0
  • Loading branch information
isqad authored Dec 6, 2021
2 parents 168e0a5 + 1cffdcf commit 593b3eb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
20 changes: 14 additions & 6 deletions lib/treasury/pgq/event.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# frozen_string_literal: true

module Treasury
module Pgq
class Event
TYPE_INSERT = 'I'.freeze
TYPE_UPDATE = 'U'.freeze
TYPE_DELETE = 'D'.freeze
TYPE_INSERT = 'I'
TYPE_UPDATE = 'U'
TYPE_DELETE = 'D'

PARAMS_SEPARATOR = '&'
KV_SEPARATOR = '='
private_constant :PARAMS_SEPARATOR, :KV_SEPARATOR

attr_accessor :id, :type, :birth_time, :txid, :ev_data, :extra1, :extra2, :extra3, :extra4

Expand Down Expand Up @@ -76,9 +82,11 @@ def no_data_changed?

def simple_parse_query(query)
return {} if query.nil?
query.split('&').inject(HashWithIndifferentAccess.new) do |result, item|
k, v = item.split('=')
result.merge!(k => v)

query.split(PARAMS_SEPARATOR).each_with_object(HashWithIndifferentAccess.new) do |item, result|
k, v = item.split(KV_SEPARATOR)

result[k] = v
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/treasury/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Treasury
VERSION = '1.10.0'
VERSION = '1.11.0'
end
9 changes: 7 additions & 2 deletions lib/treasury/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ class Worker

REFRESH_FIELDS_LIST_PERIOD = Rails.env.staging? || !Rails.env.production? ? 1.minute : 1.minute
IDLE_MAX_LAG = 2.minutes
PROCESS_LOOP_NORMAL_SLEEP_TIME = Rails.env.test? ? 0 : 0.seconds
PROCESS_LOOP_IDLE_SLEEP_TIME = Rails.env.test? ? 0 : 5.seconds
PROCESS_LOOP_NORMAL_SLEEP_TIME = Rails.env.test? ? 0 : 0.5
PROCESS_LOOP_IDLE_SLEEP_TIME = Rails.env.test? ? 0 : 5

LOGGER_FILE_NAME = "#{ROOT_LOGGER_DIR}/workers/%{name}_worker".freeze

Expand All @@ -20,6 +20,7 @@ class UnknownWorkerError < StandardError; end
def self.run(worker_id)
worker = Models::Worker.find(worker_id)
raise UnknownWorkerError if worker.nil?

self.name = worker.name
self.new(worker).process
end
Expand All @@ -36,12 +37,15 @@ def process
logger.warn "Worker запущен"
begin
return unless check_active

set_state(STATE_RUNNING)
clear_last_error
while true
break unless check_terminate

processed = process_fields
break if !processed && Rails.env.test?

idle(processed)
end
rescue Exception => e
Expand Down Expand Up @@ -99,6 +103,7 @@ def process_fields
end
rescue StandardError, NotImplementedError => e
raise if Rails.env.test?

logger.error "Ошибка при обработке поля #{field.title}:"
log_error(e)
end
Expand Down

0 comments on commit 593b3eb

Please sign in to comment.