taskman

package
v2.1.14+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2018 License: Apache-2.0 Imports: 23 Imported by: 0

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"
)

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 RegisterTask

func RegisterTask(task interface{})

Types

type IBatchTask

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

type ISingleTask

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

type ITask

type ITask interface {
	ScheduleRun(data jsonutils.JSONObject)
	GetParams() *jsonutils.JSONDict
	GetUserCred() mcclient.TokenCredential
	GetTaskId() string
	SetStage(stageName string, data *jsonutils.JSONDict)

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

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:"ascii" 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"` // 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:"ascii" 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:"ascii" 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() 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) 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) error

func (*STask) GetRequestContext

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

func (*STask) GetTaskId

func (self *STask) GetTaskId() string

func (*STask) GetUserCred

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

func (*STask) IsCurrentStageComplete

func (self *STask) IsCurrentStageComplete() 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 string)

func (*STask) SaveRequestContext

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

func (*STask) ScheduleRun

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

func (*STask) SetPendingUsage

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

func (*STask) SetStage

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

func (*STask) SetStageComplete

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

func (*STask) SetStageFailed

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

func (*STask) ValidateDeleteCondition

func (self *STask) ValidateDeleteCondition(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) 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, ownerProjId string) *sqlchemy.SQuery

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)

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