-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
458 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package exceptions | ||
|
||
import "fmt" | ||
|
||
type ErrTimer struct { | ||
Message string | ||
} | ||
|
||
func (e ErrTimer) Error() string { | ||
return e.Message | ||
} | ||
|
||
type ErrTimerExistTask struct { | ||
Name string | ||
Message string | ||
} | ||
|
||
func (e ErrTimerExistTask) Error() string { | ||
if len(e.Message) == 0 { | ||
return fmt.Sprintf("任务 %s 已存在", e.Name) | ||
} | ||
return fmt.Sprintf("任务 %s 已存在,%s", e.Name, e.Message) | ||
} | ||
|
||
func (e ErrTimerExistTask) Exist() bool { | ||
return true | ||
} | ||
|
||
type ErrTimerRun struct { | ||
Name string | ||
Message string | ||
} | ||
|
||
func (e ErrTimerRun) Error() string { | ||
if len(e.Message) == 0 { | ||
return fmt.Sprintf("任务 %s 执行失败", e.Name) | ||
} | ||
return fmt.Sprintf("任务 %s 执行失败,%s", e.Name, e.Message) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package timer | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/google/uuid" | ||
"github.com/wetor/AnimeGo/internal/api" | ||
) | ||
|
||
const ( | ||
DefaultUpdateSecond = 1 | ||
DefaultRetryCount = 1 | ||
) | ||
|
||
type TaskFunc func() error | ||
|
||
type Options struct { | ||
Name string | ||
|
||
Cache api.Cacher | ||
RetryCount int | ||
UpdateSecond int | ||
|
||
WG *sync.WaitGroup | ||
} | ||
|
||
func (o *Options) Default() { | ||
if o.RetryCount == 0 { | ||
o.RetryCount = DefaultRetryCount | ||
} | ||
if o.UpdateSecond == 0 { | ||
o.UpdateSecond = DefaultUpdateSecond | ||
} | ||
} | ||
|
||
type AddOptions struct { | ||
Name string | ||
Duration int64 | ||
Func TaskFunc | ||
Loop bool | ||
} | ||
|
||
func (o *AddOptions) Default() { | ||
if len(o.Name) == 0 { | ||
o.Name = uuid.NewString() | ||
} | ||
} |
Oops, something went wrong.