Class: Bosh::Director::Api::TaskHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/api/task_helper.rb

Instance Method Summary collapse

Instance Method Details

#create_task(username, type, description, deployment) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bosh/director/api/task_helper.rb', line 6

def create_task(username, type, description, deployment)
  task = Models::Task.create_with_teams(:username => username,
                             :type => type,
                             :description => description,
                             :state => :queued,
                             :deployment_name => deployment ? deployment.name : nil,
                             :timestamp => Time.now,
                             :teams => deployment ? deployment.teams : nil,
                             :checkpoint_time => Time.now)
  log_dir = File.join(Config.base_dir, 'tasks', task.id.to_s)
  task_status_file = File.join(log_dir, 'debug')
  FileUtils.mkdir_p(log_dir)

  File.open(task_status_file, 'a') do |f|
    f << format_log_message("Director Version: #{Bosh::Director::VERSION}")
    f << format_log_message("Enqueuing task: #{task.id}")
  end

  # remove old tasks
  TaskRemover.new(Config.max_tasks).remove(type)

  task.output = log_dir
  task.save
  task
end