Class: Cnvrg::Commands::Task

Inherits:
SubCommand show all
Defined in:
lib/cnvrg/cli/task.rb

Instance Method Summary collapse

Methods inherited from SubCommand

banner, is_thor_reserved_word?, subcommand_prefix

Constructor Details

#initialize(*args) ⇒ Task

Returns a new instance of Task.



5
6
7
8
9
10
11
# File 'lib/cnvrg/cli/task.rb', line 5

def initialize(*args)
  super
  unless @curr_dir.present?
    @cli.log_message("Not On Project Dir, exiting", Thor::Color::RED)
    exit(1)
  end
end

Instance Method Details

#createObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/cnvrg/cli/task.rb', line 36

def create
  @project = Cnvrg::Project.new(@curr_dir)

  task = {}
  task[:title] = ask("Task title", Thor::Color::GREEN)
  task[:type] = ask("Task Type?", Thor::Color::GREEN, :limited_to => ["exec", "data", "library", "deploy"])
  case task[:type]
  when "exec"
    task[:cmd] = ask("Command to run", Thor::Color::GREEN)
    task[:params], task[:params_path] = ask_for_params
    task[:machine] = ask_for_machine
  when "data"
    task[:dataset] = ask("Dataset slug", Thor::Color::GREEN)
    task[:query] = ask("Dataset query", Thor::Color::GREEN)
  when "library"
    task[:library] = ask("Library Slug", Thor::Color::GREEN)
    task[:params], task[:params_path] = ask_for_params
    task[:machine] = ask_for_machine
  when "deploy"
    task[:cmd] = ask("Command to run", Thor::Color::GREEN)
    task[:function] = ask("Function to run", Thor::Color::GREEN)
  end
  @task = Cnvrg::Task.new(@curr_dir, content: task)
  @task.save
  @cli.log_message("Task #{@task.title} Saved Successfuly", Thor::Color::GREEN)
end

#run(path) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/cnvrg/cli/task.rb', line 65

def run(path)
  begin
    path = "#{path}.task.yaml" unless path.end_with? '.task.yaml'
    @task = Cnvrg::Task.new(@curr_dir, path: path)
    url = @task.run
    @cli.log_message("Task: #{@task.title} is running, you can track its performance on #{url}", Thor::Color::GREEN)
  rescue => e
    @cli.log_message(e.message, Thor::Color::RED)
    @cli.log_error(e)
  end
end

#verify(path) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cnvrg/cli/task.rb', line 14

def verify(path)
  unless @curr_dir.present?
    @cli.log_message("Cant run this command because you are not in project directory", Thor::Color::RED)
    return false
  end
  @task = Cnvrg::Task.new(@curr_dir, path: path)
  begin
    @task.verify_task
  rescue StandardError => e
    @cli.log_message("An error during parsing task: #{e.message}", Thor::Color::RED)
    @cli.log_error(e)
    return false
  rescue => e
    @cli.log_error(e)
    return false
  end
  @cli.log_message("The task verified successfuly", Thor::Color::GREEN)
  return @task
end