tasks

package
v0.428.2 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const EntityFieldNameTaskID string = "keel_task_id"

EntityFieldNameTaskID is the field name used in the entity table to link to a keel task.

Variables

View Source
var ErrTaskNotFound = errors.New("task not found")

Functions

func AuthoriseTopic

func AuthoriseTopic(ctx context.Context, schema *proto.Schema, topic *proto.Task) (bool, error)

AuthoriseTopic will check that the context's identity is authorised to access the given topic in the context of the given schema.

func AuthorisedTopics

func AuthorisedTopics(ctx context.Context, schema *proto.Schema) ([]*proto.Task, error)

AuthorisedTopics returns a list of topics from the given schema for which the current context user is authorised to view.

Types

type Metrics

type Metrics struct {
	TotalCount       int        `json:"totalCount"`
	CompletedToday   int        `json:"completedToday"`
	OldestUnresolved *time.Time `json:"oldestUnresolved,omitempty"`
}

type Stats

type Stats struct {
	OpenCount            int            `json:"openCount"`
	AssignedCount        int            `json:"assignedCount"`
	DeferredCount        int            `json:"deferredCount"`
	CompletionRate       float32        `json:"completionRate"`
	CompletionTimeMedian *time.Duration `json:"completionTimeMedian,omitempty"`
	CompletionTime90     *time.Duration `json:"completionTime90P,omitempty"`
	CompletionTime99     *time.Duration `json:"completionTime99P,omitempty"`
}

type Status

type Status string
const (
	StatusNew       Status = "NEW"
	StatusAssigned  Status = "ASSIGNED"
	StatusDeferred  Status = "DEFERRED"
	StatusCompleted Status = "COMPLETED"
)

type Task

type Task struct {
	ID            string     `gorm:"column:id;primaryKey;->" json:"id"`
	Name          string     `gorm:"column:name"             json:"name"`
	Status        Status     `gorm:"column:status"           json:"status"`
	FlowRunID     *string    `gorm:"column:flow_run_id"      json:"flowRunId,omitempty"`
	CreatedAt     time.Time  `gorm:"column:created_at;->"    json:"createdAt"`
	UpdatedAt     time.Time  `gorm:"column:updated_at;->"    json:"updatedAt"`
	AssignedTo    *string    `gorm:"column:assigned_to"      json:"assignedTo,omitempty"`
	AssignedAt    *time.Time `gorm:"column:assigned_at"      json:"assignedAt,omitempty"`
	ResolvedAt    *time.Time `gorm:"column:resolved_at"      json:"resolvedAt,omitempty"`
	DeferredUntil *time.Time `gorm:"column:deferred_until"   json:"deferredUntil,omitempty"`
}

func AssignTask

func AssignTask(ctx context.Context, pbTask *proto.Task, id string, assignedTo, identityID string) (task *Task, err error)

AssignTask marks the given task as assigned to the given identity and returns it.

func CompleteTask

func CompleteTask(ctx context.Context, pbTask *proto.Task, id string, identityID string) (task *Task, err error)

CompleteTask marks the given task as completed and returns it.

func CreateTask

func CreateTask(ctx context.Context, pbTask *proto.Task, identityID string, deferUntil *time.Time, data map[string]any) (task *Task, err error)

CreateTask creates a new task and returns it.

func DeferTask

func DeferTask(ctx context.Context, pbTask *proto.Task, id string, deferUntil time.Time, identityID string) (task *Task, err error)

DeferTask marks the given task as deferred until the given date and returns it.

func GetTaskQueue

func GetTaskQueue(ctx context.Context, pbTask *proto.Task, inputs map[string]any) (tasks []*Task, err error)

GetTaskQueue returns the ordered queue of tasks for a given topic.

func NextTask

func NextTask(ctx context.Context, pbTask *proto.Task, identityID string) (task *Task, err error)

NextTask will assign and return the next available task to the authenticated identity.

func StartTask

func StartTask(ctx context.Context, pbTask *proto.Task, id string) (task *Task, err error)

StartTask triggers a flow run for the given task and assigns the run id to it.

func (Task) TableName

func (Task) TableName() string

type TaskStatus

type TaskStatus struct {
	ID         string    `gorm:"column:id;primaryKey;->" json:"id"`
	TaskID     string    `gorm:"column:keel_task_id"     json:"taskId"`
	Status     Status    `gorm:"column:status"           json:"status"`
	AssignedTo *string   `gorm:"column:assigned_to"      json:"assignedTo,omitempty"`
	SetBy      string    `gorm:"column:set_by"           json:"setBy"`
	CreatedAt  time.Time `gorm:"column:created_at;->"    json:"createdAt"`
}

TaskStatus represents a log of status updates for a particular task.

func (TaskStatus) TableName

func (TaskStatus) TableName() string

type Topic

type Topic struct {
	Name    string   `json:"name"`
	Metrics *Metrics `json:"metrics,omitempty"`
	Stats   *Stats   `json:"stats,omitempty"`
}

func GetTopic

func GetTopic(ctx context.Context, pbTask *proto.Task, withStats bool) (*Topic, error)

GetTopic returns the topic data (with metrics).