From 67380090817601b28fc28aba21d9a0c8c642fcb0 Mon Sep 17 00:00:00 2001 From: loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Date: Sun, 6 Jun 2021 21:05:27 +0800 Subject: [PATCH] Fix lint and format code in task dir --- CHANGELOG.md | 1 + task/govenor_command.go | 7 ++----- task/task.go | 7 ++----- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 057e5a39..60d09d8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ - Feature issue #4402 finish router get example. [4416](https://github.com/beego/beego/pull/4416) - Proposal: Add Bind() method for `web.Controller` [4491](https://github.com/beego/beego/issues/4579) - Optimize AddAutoPrefix: only register one router in case-insensitive mode. [4582](https://github.com/beego/beego/pull/4582) +- Fix lint and format code in task dir [4655](https://github.com/beego/beego/pull/4655) - Init exceptMethod by using reflection. [4583](https://github.com/beego/beego/pull/4583) - Deprecated BeeMap and replace all usage with `sync.map` [4616](https://github.com/beego/beego/pull/4616) - TaskManager support graceful shutdown [4635](https://github.com/beego/beego/pull/4635) diff --git a/task/govenor_command.go b/task/govenor_command.go index 20238435..5435fdf1 100644 --- a/task/govenor_command.go +++ b/task/govenor_command.go @@ -24,8 +24,7 @@ import ( "github.com/beego/beego/v2/core/admin" ) -type listTaskCommand struct { -} +type listTaskCommand struct{} func (l *listTaskCommand) Execute(params ...interface{}) *admin.Result { resultList := make([][]string, 0, len(globalTaskManager.adminTaskList)) @@ -45,8 +44,7 @@ func (l *listTaskCommand) Execute(params ...interface{}) *admin.Result { } } -type runTaskCommand struct { -} +type runTaskCommand struct{} func (r *runTaskCommand) Execute(params ...interface{}) *admin.Result { if len(params) == 0 { @@ -83,7 +81,6 @@ func (r *runTaskCommand) Execute(params ...interface{}) *admin.Result { Error: errors.New(fmt.Sprintf("task with name %s not found", tn)), } } - } func registerCommands() { diff --git a/task/task.go b/task/task.go index 2bec0cc7..09a08144 100644 --- a/task/task.go +++ b/task/task.go @@ -137,7 +137,6 @@ type Task struct { // NewTask add new task with name, time and func func NewTask(tname string, spec string, f TaskFunc, opts ...Option) *Task { - task := &Task{ Taskname: tname, DoFunc: f, @@ -351,7 +350,6 @@ func (t *Task) parseSpec(spec string) *Schedule { // Next set schedule to next time func (s *Schedule) Next(t time.Time) time.Time { - // Start at the earliest possible time (the upcoming second). t = t.Add(1*time.Second - time.Duration(t.Nanosecond())*time.Nanosecond) @@ -548,7 +546,7 @@ func (m *taskManager) markManagerStop() { // runNextTasks it runs next task which next run time is equal to effective func (m *taskManager) runNextTasks(sortList *MapSorter, effective time.Time) { // Run every entry whose next time was this effective time. - var i = 0 + i := 0 for _, e := range sortList.Vals { i++ if e.GetNext(context.Background()) != effective { @@ -617,7 +615,6 @@ func (m *taskManager) AddTask(taskname string, t Tasker) { m.changed <- true }() } - } // DeleteTask delete task with name @@ -690,6 +687,7 @@ func (ms *MapSorter) Less(i, j int) bool { } return ms.Vals[i].GetNext(context.Background()).Before(ms.Vals[j].GetNext(context.Background())) } + func (ms *MapSorter) Swap(i, j int) { ms.Vals[i], ms.Vals[j] = ms.Vals[j], ms.Vals[i] ms.Keys[i], ms.Keys[j] = ms.Keys[j], ms.Keys[i] @@ -708,7 +706,6 @@ func getField(field string, r bounds) uint64 { // getRange returns the bits indicated by the given expression: // number | number "-" number [ "/" number ] func getRange(expr string, r bounds) uint64 { - var ( start, end, step uint rangeAndStep = strings.Split(expr, "/")