Add Admin CronTask functions (#406)
Add Admin CronTask functions Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/406 Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
parent
18f39029e9
commit
fb7de7ecb8
2 changed files with 54 additions and 0 deletions
43
gitea/admin_cron.go
Normal file
43
gitea/admin_cron.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
// 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, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.13.0"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
opt.setDefaults()
|
||||
ct := make([]*CronTask, 0, opt.PageSize)
|
||||
return ct, c.getParsedResponse("GET", fmt.Sprintf("/admin/cron?%s", opt.getURLQuery().Encode()), jsonHeader, nil, &ct)
|
||||
}
|
||||
|
||||
// RunCronTasks run a cron task
|
||||
func (c *Client) RunCronTasks(task string) error {
|
||||
if err := c.CheckServerVersionConstraint(">=1.13.0"); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := c.getResponse("POST", fmt.Sprintf("/admin/cron/%s", task), jsonHeader, nil)
|
||||
return err
|
||||
}
|
|
@ -36,3 +36,14 @@ func TestAdminOrg(t *testing.T) {
|
|||
err = c.DeleteOrg(orgName)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestAdminCronTasks(t *testing.T) {
|
||||
log.Println("== TestAdminCronTasks ==")
|
||||
c := newTestClient()
|
||||
|
||||
tasks, err := c.ListCronTasks(ListCronTaskOptions{})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, tasks, 15)
|
||||
|
||||
assert.NoError(t, c.RunCronTasks(tasks[0].Name))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue