Beispiel #1
0
// RunHandler starts the given task identifier by it's handler. The same
// restrictions in Run() apply to this function.
// Return values are the same as Run().
func RunHandler(ctx *app.Context, handler app.Handler) (bool, error) {
	var task *Task
	p := reflect.ValueOf(handler).Pointer()
	registered.RLock()
	for _, v := range registered.tasks {
		if reflect.ValueOf(v.Handler).Pointer() == p {
			task = v
			break
		}
	}
	registered.RUnlock()
	if task == nil {
		return false, fmt.Errorf("there's no task registered with the handler %s", runtimeutil.FuncName(handler))
	}
	return executeTask(ctx, task)
}
Beispiel #2
0
// Name returns the task name.
func (t *Task) Name() string {
	if t.name != "" {
		return t.name
	}
	return runtimeutil.FuncName(t.Handler)
}