runcible / lib / runcible / resources / task.rb @ 27b106f4
1 |
module Runcible |
---|---|
2 |
module Resources |
3 |
# @see https://docs.pulpproject.org/dev-guide/integration/rest-api/dispatch/index.html
|
4 |
class Task < Runcible::Base |
5 |
# Generates the API path for Tasks
|
6 |
#
|
7 |
# @param [String] id the id of the task
|
8 |
# @return [String] the task path, may contain the id if passed
|
9 |
def self.path(id = nil) |
10 |
id.nil? ? 'tasks/' : "tasks/#{id}/" |
11 |
end
|
12 |
|
13 |
# Polls for the status of a task
|
14 |
#
|
15 |
# @param [String] id the id of the task
|
16 |
# @return [RestClient::Response]
|
17 |
def poll(id) |
18 |
call(:get, path(id))
|
19 |
end
|
20 |
|
21 |
# Cancels a task
|
22 |
#
|
23 |
# @param [String] id the id of the task
|
24 |
# @return [RestClient::Response]
|
25 |
def cancel(id) |
26 |
#cancelling a task may require cancelling some higher level
|
27 |
# task, so query the tasks _href field to make sure
|
28 |
call(:delete, poll(id)['_href']) |
29 |
end
|
30 |
|
31 |
# List all tasks based on a set of tags
|
32 |
#
|
33 |
# @param [Array] tags array of tags to scope the list on
|
34 |
# @return [RestClient::Response]
|
35 |
def list(tags = []) |
36 |
call(:get, path, :params => {:tag => tags}) |
37 |
end
|
38 |
|
39 |
# Polls all tasks based on array of IDs
|
40 |
# temporary solution until https://bugzilla.redhat.com/show_bug.cgi?id=860089
|
41 |
#
|
42 |
# @param [Array] ids array of ids to poll the status of
|
43 |
# @return [Array] array of RestClient::Response task poll objects
|
44 |
def poll_all(ids) |
45 |
return ids.map { |id| poll(id) }
|
46 |
end
|
47 |
end
|
48 |
end
|
49 |
end
|