taskman

package
v0.3.10-0-alpha2 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: Apache-2.0 Imports: 34 Imported by: 10

Documentation

Index

Constants

View Source
const (
	SUBTASK_INIT = "init"
	SUBTASK_FAIL = "fail"
	SUBTASK_SUCC = "succ"
)
View Source
const (
	PARENT_TASK_ID_KEY     = "parent_task_id"
	PENDING_USAGE_KEY      = "__pending_usage__"
	PARENT_TASK_NOTIFY_KEY = "__parent_task_notifyurl"
	REQUEST_CONTEXT_KEY    = "__request_context"

	TASK_STAGE_FAILED   = "failed"
	TASK_STAGE_COMPLETE = "complete"

	MAX_REMOTE_NOTIFY_TRIES = 5

	MULTI_OBJECTS_ID = "[--MULTI_OBJECTS--]"

	TASK_INIT_STAGE = "on_init"

	CONVERT_TASK = "convert_task"

	LANG = "lang"
)

Variables

View Source
var IBatchTaskType reflect.Type
View Source
var ITaskType reflect.Type

Functions

func AddTaskHandler

func AddTaskHandler(prefix string, app *appsrv.Application)

func Error2TaskData

func Error2TaskData(err error) jsonutils.JSONObject

func LocalTaskRun

func LocalTaskRun(task ITask, proc func() (jsonutils.JSONObject, error))

func LocalTaskRunWithWorkers

func LocalTaskRunWithWorkers(task ITask, proc func() (jsonutils.JSONObject, error), wm *appsrv.SWorkerManager)

func RegisterTask

func RegisterTask(task interface{})

func RegisterTaskAndWorker

func RegisterTaskAndWorker(task interface{}, workerMan *appsrv.SWorkerManager)

func SetServiceUrl

func SetServiceUrl(url string)

Types

type IBatchTask

type IBatchTask interface {
	OnInit(ctx context.Context, objs []db.IStandaloneModel, body jsonutils.JSONObject)
	ScheduleRun(data jsonutils.JSONObject) error
}

type ISingleTask

type ISingleTask interface {
	OnInit(ctx context.Context, obj db.IStandaloneModel, body jsonutils.JSONObject)
	ScheduleRun(data jsonutils.JSONObject) error
}

type ITask

type ITask interface {
	GetStartTime() time.Time

	ScheduleRun(data jsonutils.JSONObject) error
	GetParams() *jsonutils.JSONDict
	GetUserCred() mcclient.TokenCredential
	GetTaskId() string
	SetStage(stageName string, data *jsonutils.JSONDict) error

	GetTaskRequestHeader() http.Header

	SetStageComplete(ctx context.Context, data *jsonutils.JSONDict)
	SetStageFailed(ctx context.Context, reason jsonutils.JSONObject)

	GetPendingUsage(quota quotas.IQuota, index int) error
	ClearPendingUsage(index int) error
}

type SSubTask

type SSubTask struct {
	db.SModelBase

	TaskId    string `width:"36" charset:"ascii" nullable:"false" primary:"true"` // Column(VARCHAR(36, charset='ascii'), nullable=False, primary_key=True)
	Stage     string `width:"64" charset:"ascii" nullable:"false" primary:"true"` // Column(VARCHAR(64, charset='ascii'), nullable=False, primary_key=True)
	SubtaskId string `width:"36" charset:"ascii" nullable:"false" primary:"true"` // Column(VARCHAR(36, charset='ascii'), nullable=False, primary_key=True)
	Status    string `width:"36" charset:"ascii" nullable:"false" default:"init"` // Column(VARCHAR(36, charset='ascii'), nullable=False, default=SUBTASK_INIT)
	Result    string `length:"medium" charset:"utf8" nullable:"true"`             // Column(MEDIUMTEXT(charset='ascii'), nullable=True)
}

func (*SSubTask) SaveResults

func (self *SSubTask) SaveResults(failed bool, result jsonutils.JSONObject) error

type SSubTaskmanager

type SSubTaskmanager struct {
	db.SModelBaseManager
}
var SubTaskManager *SSubTaskmanager

func (*SSubTaskmanager) GetInitSubtasks

func (manager *SSubTaskmanager) GetInitSubtasks(taskId string, stage string) []SSubTask

func (*SSubTaskmanager) GetSubTask

func (manager *SSubTaskmanager) GetSubTask(ptaskId string, subtaskId string) *SSubTask

func (*SSubTaskmanager) GetTotalSubtasks

func (manager *SSubTaskmanager) GetTotalSubtasks(taskId string, stage string, status string) []SSubTask

type STask

type STask struct {
	db.SResourceBase

	Id string `width:"36" charset:"ascii" primary:"true" list:"user"` // Column(VARCHAR(36, charset='ascii'), primary_key=True, default=get_uuid)

	ObjName  string                   `width:"128" charset:"utf8" nullable:"false" list:"user"`               //  Column(VARCHAR(128, charset='utf8'), nullable=False)
	ObjId    string                   `width:"128" charset:"ascii" nullable:"false" list:"user" index:"true"` // Column(VARCHAR(ID_LENGTH, charset='ascii'), nullable=False)
	TaskName string                   `width:"64" charset:"ascii" nullable:"false" list:"user"`               // Column(VARCHAR(64, charset='ascii'), nullable=False)
	UserCred mcclient.TokenCredential `width:"1024" charset:"utf8" nullable:"false" get:"user"`               // Column(VARCHAR(1024, charset='ascii'), nullable=False)
	// OwnerCred string `width:"512" charset:"ascii" nullable:"true"` // Column(VARCHAR(512, charset='ascii'), nullable=True)
	Params *jsonutils.JSONDict `charset:"utf8" length:"medium" nullable:"false" get:"user"` // Column(MEDIUMTEXT(charset='ascii'), nullable=False)

	Stage string `width:"64" charset:"ascii" nullable:"false" default:"on_init" list:"user"` // Column(VARCHAR(64, charset='ascii'), nullable=False, default='on_init')
	// contains filtered or unexported fields
}

func (*STask) AllowDeleteItem

func (self *STask) AllowDeleteItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool

func (*STask) AllowGetDetails

func (self *STask) AllowGetDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool

func (*STask) AllowUpdateItem

func (self *STask) AllowUpdateItem(ctx context.Context, userCred mcclient.TokenCredential) bool

func (*STask) BeforeInsert

func (self *STask) BeforeInsert()

func (*STask) ClearPendingUsage

func (self *STask) ClearPendingUsage(index int) error

func (*STask) GetId

func (self *STask) GetId() string

func (*STask) GetName

func (self *STask) GetName() string

func (*STask) GetObject

func (self *STask) GetObject() db.IStandaloneModel

func (*STask) GetObjectIdStr

func (self *STask) GetObjectIdStr() string

func (*STask) GetObjects

func (self *STask) GetObjects() []db.IStandaloneModel

func (*STask) GetOwnerId

func (self *STask) GetOwnerId() mcclient.IIdentityProvider

func (*STask) GetParams

func (self *STask) GetParams() *jsonutils.JSONDict

func (*STask) GetParentTask

func (self *STask) GetParentTask() *STask

func (*STask) GetPendingUsage

func (self *STask) GetPendingUsage(quota quotas.IQuota, index int) error

func (*STask) GetRequestContext

func (self *STask) GetRequestContext() appctx.AppContextData

func (*STask) GetStartTime

func (task *STask) GetStartTime() time.Time

func (*STask) GetTaskId

func (self *STask) GetTaskId() string

func (*STask) GetTaskRequestHeader

func (task *STask) GetTaskRequestHeader() http.Header

func (*STask) GetUserCred

func (self *STask) GetUserCred() mcclient.TokenCredential

func (*STask) HasParentTask

func (self *STask) HasParentTask() bool

func (*STask) IsCurrentStageComplete

func (self *STask) IsCurrentStageComplete() bool

func (*STask) IsSubtask

func (self *STask) IsSubtask() bool

func (*STask) NotifyParentTaskComplete

func (self *STask) NotifyParentTaskComplete(ctx context.Context, body *jsonutils.JSONDict, failed bool)

func (*STask) NotifyParentTaskFailure

func (self *STask) NotifyParentTaskFailure(ctx context.Context, reason jsonutils.JSONObject)

func (*STask) PreCheckPerformAction

func (manager *STask) PreCheckPerformAction(
	ctx context.Context, userCred mcclient.TokenCredential,
	action string, query jsonutils.JSONObject, data jsonutils.JSONObject,
) error

func (*STask) SaveParams

func (self *STask) SaveParams(data *jsonutils.JSONDict) error

func (*STask) SaveRequestContext

func (self *STask) SaveRequestContext(data *appctx.AppContextData)

func (*STask) ScheduleRun

func (task *STask) ScheduleRun(data jsonutils.JSONObject) error

func (*STask) SetPendingUsage

func (self *STask) SetPendingUsage(quota quotas.IQuota, index int) error

func (*STask) SetStage

func (self *STask) SetStage(stageName string, data *jsonutils.JSONDict) error

func (*STask) SetStageComplete

func (self *STask) SetStageComplete(ctx context.Context, data *jsonutils.JSONDict)

func (*STask) SetStageFailed

func (self *STask) SetStageFailed(ctx context.Context, reason jsonutils.JSONObject)

func (*STask) ValidateDeleteCondition

func (self *STask) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error

func (*STask) ValidateUpdateCondition

func (self *STask) ValidateUpdateCondition(ctx context.Context) error

type STaskManager

type STaskManager struct {
	db.SResourceBaseManager
}
var TaskManager *STaskManager

func (*STaskManager) AllowCreateItem

func (manager *STaskManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool

func (*STaskManager) AllowListItems

func (manager *STaskManager) AllowListItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool

func (*STaskManager) AllowPerformAction

func (manager *STaskManager) AllowPerformAction(ctx context.Context, userCred mcclient.TokenCredential, action string, query jsonutils.JSONObject, data jsonutils.JSONObject) bool

func (*STaskManager) CreateByInsertOrUpdate

func (manager *STaskManager) CreateByInsertOrUpdate() bool

func (*STaskManager) FetchIncompleteTasksOfObject

func (manager *STaskManager) FetchIncompleteTasksOfObject(obj db.IStandaloneModel) ([]STask, error)

func (*STaskManager) FetchTaskById

func (manager *STaskManager) FetchTaskById(taskId string) *STask

func (*STaskManager) FetchTasksOfObject

func (manager *STaskManager) FetchTasksOfObject(obj db.IStandaloneModel, since time.Time, isOpen *bool) ([]STask, error)

func (*STaskManager) FetchTasksOfObjectLatest

func (manager *STaskManager) FetchTasksOfObjectLatest(obj db.IStandaloneModel, interval time.Duration, isOpen *bool) ([]STask, error)

func (*STaskManager) FilterById

func (manager *STaskManager) FilterById(q *sqlchemy.SQuery, idStr string) *sqlchemy.SQuery

func (*STaskManager) FilterByName

func (manager *STaskManager) FilterByName(q *sqlchemy.SQuery, name string) *sqlchemy.SQuery

func (*STaskManager) FilterByNotId

func (manager *STaskManager) FilterByNotId(q *sqlchemy.SQuery, idStr string) *sqlchemy.SQuery

func (*STaskManager) FilterByOwner

func (manager *STaskManager) FilterByOwner(q *sqlchemy.SQuery, owner mcclient.IIdentityProvider, scope rbacutils.TRbacScope) *sqlchemy.SQuery

func (*STaskManager) IsInTask

func (manager *STaskManager) IsInTask(obj db.IStandaloneModel) bool

func (*STaskManager) NewParallelTask

func (manager *STaskManager) NewParallelTask(
	ctx context.Context,
	taskName string,
	objs []db.IStandaloneModel,
	userCred mcclient.TokenCredential,
	taskData *jsonutils.JSONDict,
	parentTaskId string,
	parentTaskNotifyUrl string,
	pendingUsage ...quotas.IQuota,
) (*STask, error)

func (*STaskManager) NewTask

func (manager *STaskManager) NewTask(
	ctx context.Context,
	taskName string,
	obj db.IStandaloneModel,
	userCred mcclient.TokenCredential,
	taskData *jsonutils.JSONDict,
	parentTaskId string,
	parentTaskNotifyUrl string,
	pendingUsage ...quotas.IQuota,
) (*STask, error)

func (*STaskManager) PerformAction

func (manager *STaskManager) PerformAction(ctx context.Context, userCred mcclient.TokenCredential, taskId string, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error)

func (*STaskManager) QueryTasksOfObject

func (manager *STaskManager) QueryTasksOfObject(obj db.IStandaloneModel, since time.Time, isOpen *bool) *sqlchemy.SQuery

type STaskObject

type STaskObject struct {
	db.SModelBase

	TaskId string `width:"36" charset:"ascii" nullable:"false" primary:"true" index:"true"` // Column(VARCHAR(36, charset='ascii'), nullable=False, primary_key=True, index=True)
	ObjId  string `width:"36" charset:"ascii" nullable:"false" primary:"true"`              // Column(VARCHAR(36, charset='ascii'), nullable=False, primary_key=True)
}

type STaskObjectManager

type STaskObjectManager struct {
	db.SModelBaseManager
}
var TaskObjectManager *STaskObjectManager

func (*STaskObjectManager) GetObjectIds

func (manager *STaskObjectManager) GetObjectIds(task *STask) []string

Jump to

Keyboard shortcuts

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