2020-10-14 09:36:00 +05:30
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package gitea
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CronTask represents a Cron task
|
|
|
|
type CronTask struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Schedule string `json:"schedule"`
|
|
|
|
Next time.Time `json:"next"`
|
|
|
|
Prev time.Time `json:"prev"`
|
|
|
|
ExecTimes int64 `json:"exec_times"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListCronTaskOptions list options for ListCronTasks
|
|
|
|
type ListCronTaskOptions struct {
|
|
|
|
ListOptions
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListCronTasks list available cron tasks
|
|
|
|
func (c *Client) ListCronTasks(opt ListCronTaskOptions) ([]*CronTask, *Response, error) {
|
2021-01-28 22:26:38 +05:30
|
|
|
if err := c.checkServerVersionGreaterThanOrEqual(version1_13_0); err != nil {
|
2020-10-14 09:36:00 +05:30
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
opt.setDefaults()
|
|
|
|
ct := make([]*CronTask, 0, opt.PageSize)
|
|
|
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/admin/cron?%s", opt.getURLQuery().Encode()), jsonHeader, nil, &ct)
|
|
|
|
return ct, resp, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// RunCronTasks run a cron task
|
|
|
|
func (c *Client) RunCronTasks(task string) (*Response, error) {
|
2021-01-28 22:26:38 +05:30
|
|
|
if err := c.checkServerVersionGreaterThanOrEqual(version1_13_0); err != nil {
|
2020-10-14 09:36:00 +05:30
|
|
|
return nil, err
|
|
|
|
}
|
2021-03-22 22:33:18 +05:30
|
|
|
if err := escapeValidatePathSegments(&task); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-10-14 09:36:00 +05:30
|
|
|
_, resp, err := c.getResponse("POST", fmt.Sprintf("/admin/cron/%s", task), jsonHeader, nil)
|
|
|
|
return resp, err
|
|
|
|
}
|