Skip to content

Commit

Permalink
Run partition removing hook (#1143)
Browse files Browse the repository at this point in the history
* Run partition removing hook
  • Loading branch information
dmitry-sinina authored Jun 20, 2022
1 parent 1f81b96 commit 3848dfb
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions app/jobs/jobs/partition_removing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ def partition_remove_delay
YetiConfig.partition_remove_delay
end

def execute_cmd(cmd)
Open3.popen3(cmd) do |_stdin, _stdout, _stderr, wait_thr|
return wait_thr.value # Process::Status object returned.
end
end

def remove_partition!(partition_class, model_class)
table_name = model_class.table_name
remove_delay = partition_remove_delay[table_name]
Expand All @@ -40,7 +46,24 @@ def remove_partition!(partition_class, model_class)
end

cdr_remove_candidate = cdr_collection.first

if YetiConfig.partition_remove_hook.present?
cmd = "#{YetiConfig.partition_remove_hook} #{cdr_remove_candidate.class} #{cdr_remove_candidate.parent_table} #{cdr_remove_candidate.name}"
logger.info { "Running partition removing hook: #{cmd}" }
return_value = execute_cmd(cmd)
if return_value.success?
logger.info { "Partition remove hook succeed, exit code: #{return_value.exitstatus}" }
else
logger.info { "Partition remove hook failed: #{return_value.exitstatus}. Stopping removing procedure" }
return
end
end

cdr_remove_candidate.destroy!
rescue Errno::ENOENT => e
# usually raised on hook execution
logger.error { "Partition removing hook failed #{self.class}: {#{table_name}} #{cdr_remove_candidate&.name} - #{e.message}" }
capture_error(e, extra: { partition_class: partition_class, model_class: model_class })
rescue ActiveRecord::RecordNotDestroyed => e
logger.error { "#{self.class}: {#{table_name}} #{cdr_remove_candidate&.name} - #{e.message}" }
capture_error(e, extra: { partition_class: partition_class, model_class: model_class })
Expand Down

0 comments on commit 3848dfb

Please sign in to comment.