Class: SchwarmCli::Commands::Tasks

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

Constant Summary

Constants inherited from Base

Base::DEFAULT_LIST_LIMIT

Instance Method Summary collapse

Methods inherited from Base

pagination_options

Instance Method Details

#archive(id) ⇒ Object



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

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

#createObject



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

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



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

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

#listObject



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

def list
  handle_errors do
    data = fetch_paged { |page_params| client.tasks.list(**list_attrs, **page_params) }
    output_list(data, columns: [%w[ID id], %w[NAME name], %w[STATUS status],
                                %w[REPO github_repository_name], %w[CREATED created_at]])
  end
end

#message(id) ⇒ Object



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

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



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

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

#reset(id) ⇒ Object



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

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

#retry(id) ⇒ Object



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

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

#show(id) ⇒ Object



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

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



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

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

#update(id) ⇒ Object



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

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