Class: Actions::Pulp::AbstractAsyncTask
- Inherits:
-
Abstract
- Object
- Base
- Abstract
- Actions::Pulp::AbstractAsyncTask
show all
- Includes:
- Base::Polling, Dynflow::Action::Cancellable
- Defined in:
- app/lib/actions/pulp/abstract_async_task.rb
Direct Known Subclasses
Consumer::AbstractContentAction, Consumer::GenerateApplicability, Consumer::SyncCapsule, Repository::AbstractCopyContent, Repository::AbstractRemoveContent, Repository::AssociateImporter, Repository::Destroy, Repository::DistributorPublish, Repository::ImportUpload, Repository::PurgeEmptyErrata, Repository::PurgeEmptyPackageGroups, Repository::RegenerateApplicability, Repository::Sync, RepositoryGroup::Export
Constant Summary
collapse
- FINISHED_STATES =
%w(finished error canceled skipped)
Instance Method Summary
collapse
-
#cancel ⇒ Object
-
#cancel! ⇒ Object
-
#done? ⇒ Boolean
-
#external_task ⇒ Object
-
#humanized_state ⇒ Object
-
#rescue_external_task(error) ⇒ Object
-
#run(event = nil) ⇒ Object
A Task (documented pulp-dev-guide.readthedocs.org/en/latest/integration/rest-api/dispatch/task.html#task-management) Looks like: { “_href”: “/pulp/api/v2/tasks/0fe4fcab-a040-11e1-a71c-00508d977dff/”, “state”: “running”, “queue”: “[email protected]”, “task_id”: “0fe4fcab-a040-11e1-a71c-00508d977dff”, “task_type”: “pulp.server.tasks.repository.sync_with_auto_publish”, “progress_report”: {}, # contents depend on the operation “result”: null, “start_time”: “2012-05-17T16:48:00Z”, “finish_time”: null, “exception”: null, “traceback”: null, “tags”: [ “pulp:repository:f16”, “pulp:action:sync” ], “spawned_tasks”: [{“href”: “/pulp/api/v2/tasks/7744e2df-39b9-46f0-bb10-feffa2f7014b/”, “task_id”: “7744e2df-39b9-46f0-bb10-feffa2f7014b” }], “error”: null }.
Methods inherited from Abstract
#pulp_extensions, #pulp_resources
Instance Method Details
#cancel ⇒ Object
84
85
86
87
88
89
90
91
92
|
# File 'app/lib/actions/pulp/abstract_async_task.rb', line 84
def cancel
output[:pulp_tasks].each do |pulp_task|
task_resource.cancel(pulp_task['task_id'])
if pulp_task['spawned_tasks']
pulp_task['spawned_tasks'].each { |spawned| task_resource.cancel(spawned['task_id']) }
end
end
end
|
#cancel! ⇒ Object
76
77
78
79
80
81
82
|
# File 'app/lib/actions/pulp/abstract_async_task.rb', line 76
def cancel!
cancel
self.external_task = poll_external_task
suspend unless done?
end
|
#done? ⇒ Boolean
68
69
70
|
# File 'app/lib/actions/pulp/abstract_async_task.rb', line 68
def done?
external_task.all? { |task| task[:finish_time] || FINISHED_STATES.include?(task[:state]) }
end
|
#external_task ⇒ Object
72
73
74
|
# File 'app/lib/actions/pulp/abstract_async_task.rb', line 72
def external_task
output[:pulp_tasks]
end
|
#humanized_state ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'app/lib/actions/pulp/abstract_async_task.rb', line 49
def humanized_state
case state
when :running
if self.external_task.nil?
_("initiating Pulp task")
else
_("checking Pulp task status")
end
when :suspended
if external_task && external_task.all? { |task| task[:start_time].nil? }
_("waiting for Pulp to start the task")
else
_("waiting for Pulp to finish the task")
end
else
super
end
end
|
#rescue_external_task(error) ⇒ Object
94
95
96
97
98
99
100
|
# File 'app/lib/actions/pulp/abstract_async_task.rb', line 94
def rescue_external_task(error)
if error.is_a?(::Katello::Errors::PulpError)
fail error
else
super
end
end
|
#run(event = nil) ⇒ Object
A Task (documented pulp-dev-guide.readthedocs.org/en/latest/integration/rest-api/dispatch/task.html#task-management) Looks like:
"_href": "/pulp/api/v2/tasks/0fe4fcab-a040-11e1-a71c-00508d977dff/",
"state": "running",
"queue": "[email protected]",
"task_id": "0fe4fcab-a040-11e1-a71c-00508d977dff",
"task_type": "pulp.server.tasks.repository.sync_with_auto_publish",
"progress_report": {, # contents depend on the operation
"result": null,
"start_time": "2012-05-17T16:48:00Z",
"finish_time": null,
"exception": null,
"traceback": null,
"tags": [
"pulp:repository:f16",
"pulp:action:sync"
],
"spawned_tasks": [{"href": "/pulp/api/v2/tasks/7744e2df-39b9-46f0-bb10-feffa2f7014b/",
"task_id": "7744e2df-39b9-46f0-bb10-feffa2f7014b" }],
"error": null
}
42
43
44
45
46
47
|
# File 'app/lib/actions/pulp/abstract_async_task.rb', line 42
def run(event = nil)
unless event == Dynflow::Action::Skip
super
end
end
|