Untitled

 avatar
unknown
ruby
10 months ago
1.6 kB
9
Indexable
def inventory_cron
  report_start_time = Time.now
  reshuffle_config = WarehouseService.settings.inventory_reshuffle_config_v2
  reshuffle_config_v1 = WarehouseService.settings.inventory_reshuffle_config
  cron_id = Time.now.to_i.to_s + '_inventory_swap'
  success_count = 0
  failure_count = 0
  reshuffle_config.keys.each do |warehouse_id|
    next if reshuffle_config_v1.has_key?(warehouse_id)
    begin
      logger.info "Inventory_reshuffle_v2 job started at #{Time.now}"
      InventoryReshuffleV2.reshuffle(warehouse_id, reshuffle_config[warehouse_id], cron_id)
      ScMetrics.increment('inventory_reshuffle_v2.success')
      success_count += 1
    rescue Exception => e
      logger.info "INVENTORT_RESHUFFLE_V2_EXCEPTION_#{Time.now}"
      logger.info e.message
      logger.info e.backtrace
      # File.open("/var/log/flipkart/supply-chain/fk-sc-warehouse-b2b/INVENTORT_RESHUFFLE_EXCEPTION_V2_#{cron_id}", 'a') { |file| file.write("#{warehouse_id} :=> #{e.message} \n #{e.backtrace} \n\n") }
      # message_subject = "Inventory Reshuffle V2 Cron Failed!!! for #{warehouse_id}"
      # message_body =  "Cron Failed, \n exception is \n #{e.backtrace} "
      # EmailPublisher.send_mail(message_subject,message_body)
      ScMetrics.increment('inventory_reshuffle_v2.failure')
      failure_count += 1
    ensure
      report_end_time = Time.now
      report_execution_time = (report_end_time - report_start_time)* 1000
      ScMetrics.timing('inventory_reshuffle.time', report_execution_time)
    end
  end
end

def run_inventory_reshuffle_cron
  while true
    inventory_cron
    sleep 1800
  end
end
Editor is loading...
Leave a Comment