lib/acquia_toolbelt/cli/task.rb in acquia_toolbelt-2.3.2 vs lib/acquia_toolbelt/cli/task.rb in acquia_toolbelt-2.4.0
- old
+ new
@@ -6,24 +6,27 @@
#
# task - The task object that contains all the information about the
# task.
def output_task_item(task)
completion_time = (task['completed'].to_i - task['started'].to_i) / 60
- ui.say
- ui.say "Task ID: #{task['id'].to_i}"
- ui.say "Description: #{task['description']}"
- ui.say "Status: #{task['state']}"
+ row_data = []
+ description = task['description'].scan(/.{1,50}[\w\=]/).map(&:strip)
+ row_data << task['id'].to_i
+ row_data << task['queue']
+ row_data << description.join("\n")
+ row_data << task['state'].capitalize
+
# If the completion time is greater then 0, output it in minutes
# otherwise just say it was less then a minute.
if completion_time > 0
- ui.say "Completion time: About #{completion_time} minutes"
+ row_data << "About #{completion_time} minutes"
else
- ui.say 'Completion time: Less than 1 minute'
+ row_data << 'Less than 1 minute'
end
- ui.say "Queue: #{task['queue']}"
+ row_data
end
end
# Public: List all tasks from the Acquia tasks queue(s).
#
@@ -38,23 +41,31 @@
subscription = options[:subscription]
else
subscription = AcquiaToolbelt::CLI::API.default_subscription
end
- queue = options[:queue]
- count = options[:count]
+ ui.say
+ queue = options[:queue]
+ count = options[:count]
+ tasks = []
+ rows = []
+ headings = [
+ 'ID',
+ 'Queue',
+ 'Description',
+ 'State',
+ 'Completion time'
+ ]
+
all_tasks = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/tasks"
- tasks = []
# Fetch a single queue from the tasks list if the queue parameter is set
# otherwise just add all the tasks.
if queue
all_tasks.each do |task|
- if task['queue'] == queue
- tasks << task
- end
+ tasks << task if task['queue'] == queue
end
else
all_tasks.each do |task|
tasks << task
end
@@ -62,11 +73,13 @@
# If there is a count to return, restrict it to that required amount.
tasks = tasks.last(count.to_i) if count && tasks.any?
tasks.each do |task|
- output_task_item(task)
+ rows << output_task_item(task)
end
+
+ ui.output_table('', headings, rows)
end
end
end
end