Class: SchwarmCli::Commands::Tasks

Inherits:
Base
  • Object
show all
Defined in:
lib/schwarm_cli/commands/tasks.rb

Instance Method Summary collapse

Instance Method Details

#archive(id) ⇒ Object



76
77
78
79
80
81
# File 'lib/schwarm_cli/commands/tasks.rb', line 76

def archive(id)
  handle_errors do
    data = client.tasks.archive(id)
    puts "Task #{id} archived (#{data.dig('data', 'status')})."
  end
end

#createObject



39
40
41
42
43
44
# File 'lib/schwarm_cli/commands/tasks.rb', line 39

def create
  handle_errors do
    data = client.tasks.create(**create_attrs)
    output_record(data, fields: { "ID" => "id", "Name" => "name", "Status" => "status" })
  end
end

#delete(id) ⇒ Object



60
61
62
63
64
65
# File 'lib/schwarm_cli/commands/tasks.rb', line 60

def delete(id)
  handle_errors do
    client.tasks.destroy(id)
    puts "Task #{id} deleted."
  end
end

#listObject



10
11
12
13
14
15
16
# File 'lib/schwarm_cli/commands/tasks.rb', line 10

def list
  handle_errors do
    data = client.tasks.list(status: options[:status], repository_id: options[:repo], query: options[:query])
    output_list(data, columns: [%w[ID id], %w[NAME name], %w[STATUS status],
                                %w[REPO github_repository_id], %w[CREATED created_at]])
  end
end

#message(id) ⇒ Object



109
110
111
112
113
114
# File 'lib/schwarm_cli/commands/tasks.rb', line 109

def message(id)
  handle_errors do
    client.messages.create(task_id: id, content: options[:content])
    puts "Message sent to task #{id}."
  end
end

#pause(id) ⇒ Object



100
101
102
103
104
105
# File 'lib/schwarm_cli/commands/tasks.rb', line 100

def pause(id)
  handle_errors do
    data = client.tasks.pause(id)
    puts "Task #{id} paused (#{data.dig('data', 'status')})."
  end
end

#reset(id) ⇒ Object



92
93
94
95
96
97
# File 'lib/schwarm_cli/commands/tasks.rb', line 92

def reset(id)
  handle_errors do
    data = client.tasks.reset(id)
    puts "Task #{id} reset (#{data.dig('data', 'status')})."
  end
end

#retry(id) ⇒ Object



84
85
86
87
88
89
# File 'lib/schwarm_cli/commands/tasks.rb', line 84

def retry(id)
  handle_errors do
    data = client.tasks.retry(id)
    puts "Task #{id} retried (#{data.dig('data', 'status')})."
  end
end

#show(id) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/schwarm_cli/commands/tasks.rb', line 19

def show(id)
  handle_errors do
    data = client.tasks.find(id)
    output_record(data, fields: {
                    "ID" => "id", "Name" => "name", "Status" => "status", "Prompt" => "prompt",
                    "Branch" => "branch_name", "Error" => "error_message",
                    "Repository" => "github_repository_id", "Dependencies" => "dependency_ids",
                    "Created" => "created_at", "Updated" => "updated_at"
                  })
  end
end

#start(id) ⇒ Object



68
69
70
71
72
73
# File 'lib/schwarm_cli/commands/tasks.rb', line 68

def start(id)
  handle_errors do
    data = client.tasks.start(id)
    puts "Task #{id} started (#{data.dig('data', 'status')})."
  end
end

#update(id) ⇒ Object



52
53
54
55
56
57
# File 'lib/schwarm_cli/commands/tasks.rb', line 52

def update(id)
  handle_errors do
    data = client.tasks.update(id, **update_attrs)
    output_record(data, fields: { "ID" => "id", "Name" => "name", "Status" => "status" })
  end
end