taskframework

package
v0.0.0-...-7f85f33 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Copyright (c) 2020 tickstep.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2020 tickstep.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2020 tickstep.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var (
	// TaskUnitRunResultSuccess 任务执行成功
	TaskUnitRunResultSuccess = &TaskUnitRunResult{}
)

Functions

This section is empty.

Types

type TaskExecutor

type TaskExecutor struct {

	// 是否统计失败队列
	IsFailedDeque bool
	// contains filtered or unexported fields
}

func NewTaskExecutor

func NewTaskExecutor() *TaskExecutor

func (*TaskExecutor) Append

func (te *TaskExecutor) Append(unit TaskUnit, maxRetry int) *TaskInfo

Append 将任务加到任务队列末尾

func (*TaskExecutor) AppendNoRetry

func (te *TaskExecutor) AppendNoRetry(unit TaskUnit)

AppendNoRetry 将任务加到任务队列末尾, 不重试

func (*TaskExecutor) Count

func (te *TaskExecutor) Count() int

Count 返回任务数量

func (*TaskExecutor) Execute

func (te *TaskExecutor) Execute()

Execute 执行任务

func (*TaskExecutor) FailedDeque

func (te *TaskExecutor) FailedDeque() *lane.Deque

FailedDeque 获取失败队列

func (*TaskExecutor) Pause

func (te *TaskExecutor) Pause()

Pause 暂停执行

func (*TaskExecutor) Resume

func (te *TaskExecutor) Resume()

Resume 恢复执行

func (*TaskExecutor) SetParallel

func (te *TaskExecutor) SetParallel(parallel int)

设置任务的最大并发量

func (*TaskExecutor) Stop

func (te *TaskExecutor) Stop()

Stop 停止执行

type TaskInfo

type TaskInfo struct {
	// contains filtered or unexported fields
}

func (*TaskInfo) Id

func (t *TaskInfo) Id() string

func (*TaskInfo) IsExceedRetry

func (t *TaskInfo) IsExceedRetry() bool

IsExceedRetry 重试次数达到限制

func (*TaskInfo) MaxRetry

func (t *TaskInfo) MaxRetry() int

func (*TaskInfo) Retry

func (t *TaskInfo) Retry() int

func (*TaskInfo) SetMaxRetry

func (t *TaskInfo) SetMaxRetry(maxRetry int)

type TaskInfoItem

type TaskInfoItem struct {
	Info *TaskInfo
	Unit TaskUnit
}

type TaskUnit

type TaskUnit interface {
	SetTaskInfo(info *TaskInfo)
	// 执行任务
	Run() (result *TaskUnitRunResult)
	// 重试任务执行的方法
	// 当达到最大重试次数, 执行失败
	OnRetry(lastRunResult *TaskUnitRunResult)
	// 每次执行成功执行的方法
	OnSuccess(lastRunResult *TaskUnitRunResult)
	// 每次执行失败执行的方法
	OnFailed(lastRunResult *TaskUnitRunResult)
	// 每次执行结束执行的方法, 不管成功失败
	OnComplete(lastRunResult *TaskUnitRunResult)
	// 重试等待的时间
	RetryWait() time.Duration
}

type TaskUnitRunResult

type TaskUnitRunResult struct {
	Succeed   bool // 是否执行成功
	NeedRetry bool // 是否需要重试

	// 以下是额外的信息
	Err           error       // 错误信息
	ResultCode    int         // 结果代码
	ResultMessage string      // 结果描述
	Extra         interface{} // 额外的信息
}

任务单元执行结果

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL