Class: SchwarmCli::Commands::Recurring
- Inherits:
-
Base
- Object
- Thor
- Base
- SchwarmCli::Commands::Recurring
show all
- Defined in:
- lib/schwarm_cli/commands/recurring.rb
Constant Summary
Constants inherited
from Base
Base::DEFAULT_LIST_LIMIT
Instance Method Summary
collapse
Methods inherited from Base
exit_on_failure?, pagination_options
Instance Method Details
#create ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/schwarm_cli/commands/recurring.rb', line 37
def create
handle_errors do
attrs = {
name: options[:name], github_repository_id: resolve_repo(options[:repo]),
prompt: options[:prompt], cron_expression: options[:schedule]
}
data = client.recurring.create(**attrs)
output_record(data, fields: { "ID" => "id", "Name" => "name", "Schedule" => "cron_expression" })
end
end
|
#delete(id) ⇒ Object
61
62
63
64
65
66
|
# File 'lib/schwarm_cli/commands/recurring.rb', line 61
def delete(id)
handle_errors do
client.recurring.destroy(id)
puts "Recurring task #{id} deleted."
end
end
|
#list ⇒ Object
10
11
12
13
14
15
16
17
18
|
# File 'lib/schwarm_cli/commands/recurring.rb', line 10
def list
handle_errors do
data = fetch_paged do |page_params|
client.recurring.list(repository_id: resolve_repo(options[:repo]), query: options[:query], **page_params)
end
output_list(data, columns: [%w[ID id], %w[NAME name], %w[REPO github_repository_name],
%w[ENABLED enabled], %w[SCHEDULE cron_expression]])
end
end
|
#show(id) ⇒ Object
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/schwarm_cli/commands/recurring.rb', line 21
def show(id)
handle_errors do
data = client.recurring.find(id)
output_record(data, fields: {
"ID" => "id", "Name" => "name", "Repository" => "github_repository_id",
"Enabled" => "enabled", "Schedule" => "cron_expression", "Prompt" => "prompt",
"Created" => "created_at", "Updated" => "updated_at"
})
end
end
|
#toggle(id) ⇒ Object
69
70
71
72
73
74
75
|
# File 'lib/schwarm_cli/commands/recurring.rb', line 69
def toggle(id)
handle_errors do
data = client.recurring.toggle(id)
status = data.dig("data", "enabled") ? "enabled" : "disabled"
puts "Recurring task #{id} #{status}."
end
end
|
#update(id) ⇒ Object
53
54
55
56
57
58
|
# File 'lib/schwarm_cli/commands/recurring.rb', line 53
def update(id)
handle_errors do
data = client.recurring.update(id, **update_attrs)
output_record(data, fields: { "ID" => "id", "Name" => "name", "Schedule" => "cron_expression" })
end
end
|