Class: Cnvrg::Commands::Task
- Inherits:
-
SubCommand
- Object
- Thor
- SubCommand
- Cnvrg::Commands::Task
- Defined in:
- lib/cnvrg/cli/task.rb
Instance Method Summary collapse
- #create ⇒ Object
-
#initialize(*args) ⇒ Task
constructor
A new instance of Task.
- #run(path) ⇒ Object
- #verify(path) ⇒ Object
Methods inherited from SubCommand
banner, is_thor_reserved_word?, subcommand_prefix
Constructor Details
Instance Method Details
#create ⇒ Object
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.("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.("Task: #{@task.title} is running, you can track its performance on #{url}", Thor::Color::GREEN) rescue => e @cli.(e., 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.("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.("An error during parsing task: #{e.}", Thor::Color::RED) @cli.log_error(e) return false rescue => e @cli.log_error(e) return false end @cli.("The task verified successfuly", Thor::Color::GREEN) return @task end |