require_relative "worker"

class DeleteExpiredServerWorker < Worker

  def perform(options)
    server_id = options.fetch('server_id')

    owner = 'SYSTEM'
    call do |out, task|
      puts_and_flush "Expire server '#{server_id}'."
      server = Devops::Model::Server.find(server_id)

      set_task_data({
        "created_by" => owner,
        "project" => server.project,
        "deploy_env" => server.deploy_env,
        "type" => Devops::Model::JobTask::EXPIRE_SERVER_TYPE
      })

      e = Devops::Executor::ServerExecutor.new(server, out, owner)
      e.job_task = task
      e.delete_server
    end
  end

end
