<commit_before>require 'celluloid'
require_relative 'logging'
require_relative 'grid_service_scheduler'

class GridServiceDeployer
  include Logging
  include DistributedLocks

  class NodeMissingError < StandardError; end
  class DeployError < StandardError; end

  DEFAULT_REGISTRY = 'index.docker.io'

  attr_reader :grid_service, :nodes, :scheduler

  ##
  # @param [#find_node] strategy
  # @param [GridService] grid_service
  # @param [Array<HostNode>] nodes
  def initialize(strategy, grid_service, nodes)
    @scheduler = GridServiceScheduler.new(strategy)
    @grid_service = grid_service
    @nodes = nodes
  end

  ##
  # Is deploy possible?
  #
  # @return [Boolean]
  def can_deploy?
    self.grid_service.container_count.times do |i|
      node = self.scheduler.select_node(
        self.grid_service, i + 1, self.nodes
      )
      return false unless node
    end

    true
  end

  # @return [Array<HostNode>]
  def selected_nodes
    nodes = []
    self.instance_count.times do |i|
      node = self.scheduler.select_node(
        self.grid_service, i + 1, self.nodes
      )
      nodes << node if node
    end
    self.nodes.each{|n| n.schedule_counter = 0}

    nodes
  end

  def deploy
    info "starting to deploy #{self.grid_service.to_path}"
    creds = self.creds_for_registry
    self.grid_service.set_state('deploying')
    self.grid_service.set(:deployed_at => Time.now.utc)

    deploy_rev = Time.now.utc.to_s
    deploy_futures = []
    %w(TERM).each do |signal|
      Signal.trap(signal) { self.grid_service.set_state('running') }
    end
    total_instances = self.instance_count
    total_instances.times do |i|
      instance_number = i + 1<commit_msg>Remove invalid signal trap (#689)<commit_after>require 'celluloid'
require_relative 'logging'
require_relative 'grid_service_scheduler'

class GridServiceDeployer
  include Logging
  include DistributedLocks

  class NodeMissingError < StandardError; end
  class DeployError < StandardError; end

  DEFAULT_REGISTRY = 'index.docker.io'

  attr_reader :grid_service, :nodes, :scheduler

  ##
  # @param [#find_node] strategy
  # @param [GridService] grid_service
  # @param [Array<HostNode>] nodes
  def initialize(strategy, grid_service, nodes)
    @scheduler = GridServiceScheduler.new(strategy)
    @grid_service = grid_service
    @nodes = nodes
  end

  ##
  # Is deploy possible?
  #
  # @return [Boolean]
  def can_deploy?
    self.grid_service.container_count.times do |i|
      node = self.scheduler.select_node(
        self.grid_service, i + 1, self.nodes
      )
      return false unless node
    end

    true
  end

  # @return [Array<HostNode>]
  def selected_nodes
    nodes = []
    self.instance_count.times do |i|
      node = self.scheduler.select_node(
        self.grid_service, i + 1, self.nodes
      )
      nodes << node if node
    end
    self.nodes.each{|n| n.schedule_counter = 0}

    nodes
  end

  def deploy
    info "starting to deploy #{self.grid_service.to_path}"
    creds = self.creds_for_registry
    self.grid_service.set_state('deploying')
    self.grid_service.set(:deployed_at => Time.now.utc)

    deploy_rev = Time.now.utc.to_s
    deploy_futures = []
    total_instances = self.instance_count
    total_instances.times do |i|
      instance_number = i + 1
{'fraction_non_alphanumeric': 0.09662716499544212, 'fraction_numerical': 0.003342449103615922, 'mean_word_length': 3.2697795071335927, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6878695', 'n_tokens_mistral': 1124, 'n_tokens_neox': 1070, 'n_words': 241}