github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/servicestage/v2/jobs/requests.go (about)

     1  package jobs
     2  
     3  import (
     4  	"github.com/chnsz/golangsdk"
     5  	"github.com/chnsz/golangsdk/pagination"
     6  )
     7  
     8  var requestOpts = golangsdk.RequestOpts{
     9  	MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"},
    10  }
    11  
    12  // Get is a method to obtain the details of a specified deployment job using its ID.
    13  //
    14  // Deprecated: Please use the List method to query task details because of the Get method can only obtain maximum of 20
    15  // results of task (The first page).
    16  func Get(c *golangsdk.ServiceClient, jobId string) (*JobResp, error) {
    17  	var r JobResp
    18  	_, err := c.Get(rootURL(c, jobId), &r, &golangsdk.RequestOpts{
    19  		MoreHeaders: requestOpts.MoreHeaders,
    20  	})
    21  	return &r, err
    22  }
    23  
    24  // ListOpts allows to filter list data using given parameters.
    25  type ListOpts struct {
    26  	// Instance ID of the component.
    27  	InstanceId string `q:"instance_id"`
    28  	// Number of records to be queried.
    29  	// Default value: 20
    30  	Limit int `q:"limit"`
    31  	// The offset number.
    32  	Offset int `q:"offset"`
    33  	// Descending or ascending order.
    34  	Desc string `q:"desc"`
    35  }
    36  
    37  // List is a method to query the list of the deployment task using given ID and opts.
    38  func List(c *golangsdk.ServiceClient, jobId string, opts ListOpts) ([]Task, error) {
    39  	url := rootURL(c, jobId)
    40  	query, err := golangsdk.BuildQueryString(opts)
    41  	if err != nil {
    42  		return nil, err
    43  	}
    44  	url += query.String()
    45  
    46  	pages, err := pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
    47  		p := TaskPage{pagination.OffsetPageBase{PageResult: r}}
    48  		return p
    49  	}).AllPages()
    50  
    51  	if err != nil {
    52  		return nil, err
    53  	}
    54  	return ExtractTasks(pages)
    55  }