-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathadmin_task.go
124 lines (113 loc) · 5.8 KB
/
admin_task.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package api
import (
"encoding/json"
"time"
zest "github.com/content-services/zest/release/v2024"
)
// AdminTaskInfoResponse holds data returned by a admin tasks API response
type AdminTaskInfoResponse struct {
UUID string `json:"uuid"` // UUID of the object
Status string `json:"status"` // Status of task (running, failed, completed, canceled, pending)
Typename string `json:"typename"` // Type of task (e.g. introspect, completed)
QueuedAt string `json:"queued_at"` // Timestamp task was queued at
StartedAt string `json:"started_at"` // Timestamp task started running at
FinishedAt string `json:"finished_at"` // Timestamp task finished running at
Error string `json:"error"` // Error thrown while running task
OrgId string `json:"org_id"` // Organization ID of the owner
AccountId string `json:"account_id"` // Account ID of the owner
Payload json.RawMessage `json:"payload"` // Payload of task (only returned in fetch)
Pulp PulpResponse `json:"pulp,omitempty"` // Pulp data for snapshot tasks (only returned in fetch)
}
type AdminTaskInfoCollectionResponse struct {
Data []AdminTaskInfoResponse `json:"data"` // Requested Data
Meta ResponseMetadata `json:"meta"` // Metadata about the request
Links Links `json:"links"` // Links to other pages of results
}
type PulpResponse struct {
Sync *PulpTaskResponse `json:"sync,omitempty"`
Distribution *PulpTaskResponse `json:"distribution,omitempty"`
Publication *PulpTaskResponse `json:"publication,omitempty"`
}
type PulpTaskResponse struct {
PulpHref *string `json:"pulp_href,omitempty"`
// Timestamp of creation.
PulpCreated *time.Time `json:"pulp_created,omitempty"`
// The current state of the task. The possible values include: 'waiting', 'skipped', 'running', 'completed', 'failed', 'canceled' and 'canceling'.
State *string `json:"state,omitempty"`
// The name of task.
Name string `json:"name"`
// The logging correlation id associated with this task
LoggingCid string `json:"logging_cid"`
// Timestamp of the when this task started execution.
StartedAt *time.Time `json:"started_at,omitempty"`
// Timestamp of the when this task stopped execution.
FinishedAt *time.Time `json:"finished_at,omitempty"`
// A JSON Object of a fatal error encountered during the execution of this task.
Error map[string]string `json:"error,omitempty"`
// The worker associated with this task. This field is empty if a worker is not yet assigned.
Worker *string `json:"worker,omitempty"`
// The parent task that spawned this task.
ParentTask *string `json:"parent_task,omitempty"`
// Any tasks spawned by this task.
ChildTasks []string `json:"child_tasks,omitempty"`
// The task group that this task is a member of.
TaskGroup *string `json:"task_group,omitempty"`
ProgressReports []pulpProgressReportResponse `json:"progress_reports,omitempty"`
// Resources created by this task.
CreatedResources []string `json:"created_resources,omitempty"`
// A list of resources required by that task.
ReservedResourcesRecord []string `json:"reserved_resources_record,omitempty"`
}
type pulpProgressReportResponse struct {
// The message shown to the user for the progress report.
Message *string `json:"message,omitempty"`
// Identifies the type of progress report'.
Code *string `json:"code,omitempty"`
// The current state of the progress report. The possible values are: 'waiting', 'skipped', 'running', 'completed', 'failed', 'canceled' and 'canceling'. The default is 'waiting'.
State *string `json:"state,omitempty"`
// The total count of items.
Total *int64 `json:"total,omitempty"`
// The count of items already processed. Defaults to 0.
Done *int64 `json:"done,omitempty"`
// The suffix to be shown with the progress report.
Suffix zest.NullableString `json:"suffix,omitempty"`
}
type ListFeaturesResponse struct {
Features []string `json:"features"`
}
func (a *AdminTaskInfoCollectionResponse) SetMetadata(meta ResponseMetadata, links Links) {
a.Meta = meta
a.Links = links
}
func zestProgressReportToApi(zestProgressReport *zest.ProgressReportResponse, apiProgressReport *pulpProgressReportResponse) {
apiProgressReport.Message = zestProgressReport.Message
apiProgressReport.Code = zestProgressReport.Code
apiProgressReport.State = zestProgressReport.State
apiProgressReport.Total = zestProgressReport.Total
apiProgressReport.Done = zestProgressReport.Done
apiProgressReport.Suffix = zestProgressReport.Suffix
}
func ZestTaskResponseToApi(zestTaskResponse *zest.TaskResponse, apiTaskResponse *PulpTaskResponse) {
apiTaskResponse.PulpHref = zestTaskResponse.PulpHref
apiTaskResponse.PulpCreated = zestTaskResponse.PulpCreated
apiTaskResponse.State = zestTaskResponse.State
apiTaskResponse.Name = zestTaskResponse.Name
apiTaskResponse.LoggingCid = zestTaskResponse.LoggingCid
apiTaskResponse.StartedAt = zestTaskResponse.StartedAt
apiTaskResponse.FinishedAt = zestTaskResponse.FinishedAt
apiTaskResponse.Worker = zestTaskResponse.Worker
apiTaskResponse.ParentTask = zestTaskResponse.ParentTask
apiTaskResponse.ChildTasks = zestTaskResponse.ChildTasks
apiTaskResponse.TaskGroup = zestTaskResponse.TaskGroup
if zestTaskResponse.Error != nil {
apiTaskResponse.Error = *zestTaskResponse.Error
}
if len(zestTaskResponse.ProgressReports) > 0 {
apiTaskResponse.ProgressReports = make([]pulpProgressReportResponse, len(zestTaskResponse.ProgressReports))
for i := range apiTaskResponse.ProgressReports {
zestProgressReportToApi(&zestTaskResponse.ProgressReports[i], &apiTaskResponse.ProgressReports[i])
}
}
apiTaskResponse.CreatedResources = zestTaskResponse.CreatedResources
apiTaskResponse.ReservedResourcesRecord = zestTaskResponse.ReservedResourcesRecord
}