Skip to content

Commit

Permalink
fix: increase idle time for decrease cpu time
Browse files Browse the repository at this point in the history
  • Loading branch information
isqad committed Nov 10, 2021
1 parent 168e0a5 commit f5cdbf6
Showing 1 changed file with 7 additions and 2 deletions.
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 f5cdbf6

Please sign in to comment.