Untitled

 avatar
unknown
ruby
10 months ago
4.0 kB
10
Indexable
def matl_creation
  warehouse_id = 'nad_har_wh_kl_nl_01nl'
  ShardManager.new.using_shard_for_warehouse_id(warehouse_id) do
    capacity = WarehouseService.settings.warehouse_merge_sg_bin_capacity[warehouse_id]
    service = CreateMergeAreaGoodsTransferListService.new(warehouse_id)
    occupied_capacity = ship_group_service(warehouse_id).get_merge_area_occupied_capacity(warehouse_id)
    total_available_capacity = capacity - occupied_capacity
    priority = 'standard'
    pick_dispatch_slot_configuration = pick_dispatch_configurations_service(warehouse_id).get_vo_by_priority_type(priority)
    total_buffer_time = pick_dispatch_slot_configuration.pick_to_dispatch_time + WarehouseService.settings.sg_break_breached_buffer_time
    warehouse = WarehouseCache.get_warehouse_data!(warehouse_id)
    current_cutoff = ShippingData::ShipGroup.get_next_cutoffs_for_matl(warehouse, priority)
    if current_cutoff.present?
      dispatch_by_date = current_cutoff.strftime('%Y-%m-%d %H:%M:%S')
    end
    current_time = Time.now
    logger.debug "current_time : #{current_time}, current_cutoff #{current_cutoff},  buffer_time_minutes: #{total_buffer_time} "
    logger.debug "Is Cutoff Breached ?? : #{current_time > (current_cutoff - total_buffer_time.minutes)} , time diff #{current_cutoff - total_buffer_time.minutes} "
    if current_time <= (current_cutoff - total_buffer_time.minutes)
      logger.info "Started MATL Creation"
      response1 =  service.create_matl_based_on_capacity()
    end
    logger.debug "Started SG Break"
    response2 = service.break_breached_sgs()
    logger.debug "SG Break Successful"

    if response1.nil?
      logger.debug "Populating the metric data since MATL creation is not called !!! "
      response1 = {}
      response1.merge!(:bin_capacity_uploaded => capacity)
      response1.merge!(:dispatch_by_date => dispatch_by_date)
      response1.merge!(:occupied_capacity => occupied_capacity)
      response1.merge!(:total_available_capacity => total_available_capacity)
      response1.merge!(:created_merge_area_gtl => 0)
      response1.merge!(:sgs_count_planned => 0)
      response1.merge!(:inventory_item_planned => 0)
    end

    response1[:dispatch_by_date] = (Time.parse(response1[:dispatch_by_date]).to_time.to_i) * 1000
    response2[:current_fencing_time] = (response2[:current_fencing_time].to_time.to_i) * 1000
    logger.debug "Publishing Cron Report  #{response1}, #{response2}"
    publish_cron_report(response1, response2)
    logger.debug "MATL creation Cron Complete !!!!"
  end
end

def publish_cron_report(response1, response2)
  ts = Time.now.to_i
  publish_metrics(ts,'matl_creation_cron_success.bin_capacity_uploaded', response1[:bin_capacity_uploaded])
  publish_metrics(ts,'matl_creation_cron_success.dispatch_by_date', response1[:dispatch_by_date])
  publish_metrics(ts,'matl_creation_cron_success.occupied_capacity', response1[:occupied_capacity])
  publish_metrics(ts,'matl_creation_cron_success.total_available_capacity', response1[:total_available_capacity])
  publish_metrics(ts,'matl_creation_cron_success.created_merge_area_gtl', response1[:created_merge_area_gtl])
  publish_metrics(ts,'matl_creation_cron_success.sgs_count_planned', response1[:sgs_count_planned])
  publish_metrics(ts,'matl_creation_cron_success.inventory_item_planned', response1[:inventory_item_planned])
  publish_metrics(ts,'matl_creation_cron_success.total_buffer_time', response2[:total_buffer_time])
  publish_metrics(ts,'matl_creation_cron_success.current_fencing_time', response2[:current_fencing_time] )
  publish_metrics(ts,'matl_creation_cron_success.final_breached_sgs', response2[:final_breached_sgs])
  publish_metrics(ts,'matl_creation_cron_success.broken_reservation_count', response2[:broken_reservation_count])
  publish_metrics(ts,'matl_creation_cron_success.new_sg_created_count', response2[:new_sg_created_count])
end


def run_matl_creation_cron
  while true
    matl_creation
    sleep 1800
  end
end
Editor is loading...
Leave a Comment