Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
github.com/gromitlee/go-async
基于golang实现的去中心化异步任务框架
go-async特点
go get github.com/gromitlee/go-async
去中心化
系统边界
任务运行
func Init(ctx context.Context, db *gorm.DB, options ...AsyncOption) error
func Stop()
func RegisterTask(taskTyp uint32, newTask async_task.ITaskFunc) error
func CreateTask(ctx context.Context, user, group string, taskTyp uint32, taskCtx string, autoRun bool) (uint32, error)
func ChangeTaskGroup(ctx context.Context, taskID uint32, group string) error
func RunTask(ctx context.Context, taskID uint32) error
func DeleteTask(ctx context.Context, taskID uint32) error
func PauseTask(ctx context.Context, taskID uint32) error
func GetTask(ctx context.Context, taskID uint32) (*async_task.Task, error)
func GetTasks(ctx context.Context, user, group string, taskTypes []uint32, states []async_task.State, offset, limit int32) ([]*async_task.Task, error)
Init
和Stop
方法用于用户初始化和关闭go-async系统RegisterTask
和CreateTask
方法用于用户注册和创建不同类型的异步任务RunTask
、DeleteTak
和PauseTask
方法用于用户运行/继续运行、删除和暂停异步任务ChangeTaskGroup
方法用于用户变更异步任务所属队列GetTask
、GetTasks
方法用于查询异步任务,用户可见的任务状态有
StateInit
已创建StatePending
排队中StateRunning
运行中StateCanceling
取消中StatePause
暂停StateFinished
结束StateFailed
失败type IReport interface {
Phase() (RunPhase, bool)
Context() string
}
type ITask interface {
Running(ctx context.Context, taskCtx string, stop <-chan struct{}) <-chan IReport
Deleting(ctx context.Context, taskCtx string, stop <-chan struct{}) <-chan IReport
}
Running
方法用于用户实现完成异步任务业务逻辑的过程方法
ctx
是异步任务运行上下文,由go-async系统初始化时(Init
方法)指定,不会被go-async系统本身主动取消taskCtx
是异步任务执行所需的逻辑上下文,由创建异步任务时(CreateTask
方法)指定,或被异步任务本身动态更新、上报后,由go-async系统回传stop
用于接收go-async系统的停止信号,可能来自于用户手动暂停(PauseTask
方法)、删除(DeleteTask
方法)或go-async系统关闭,Running
方法运行中最多只会收到一次停止信号IReport
用于Running
方法向go-async系统上报异步任务执行情况与逻辑上下文
Context
方法用于向go-async系统上报当前的逻辑上下文,go-async系统负责存储Phase
方法用于向go-async系统上报异步任务的执行情况
RunPhaseNormal
表示任务正常执行RunPhaseFinished
表示任务结束,bool
表示是否删除对应任务记录,之后IReport
channel应当被关闭并退出执行RunPhaseFailed
表示任务失败,bool
表示是否删除对应任务记录,之后IReport
channel应当被关闭并退出执行stop
停止信号,任务根据自身情况上报后退出执行即可;一般是上报RunPhaseNormal
Deleting
方法用于用户实现删除(DeleteTask
方法)异步任务后,清理业务逻辑的过程方法,与Running
方法类似FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.