models

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback func() *TaskResponse

Callback defines the processing logic of a task.

type Request

type Request struct {
	ID               string             `json:"id"`
	Task             *Task              `json:"task"`
	ScheduledTime    time.Time          `json:"scheduled_time"`
	CompletedChannel chan *TaskResponse `json:"-"`
	Ctx              context.Context    `json:"-"`
	CreatedAt        time.Time          `json:"created_at"`
	Status           string             `json:"status"`
}

func NewRequest

func NewRequest(ctx context.Context, task *Task, scheduledTime time.Time) *Request

NewRequest creates a new job request with a single task.

func (*Request) IsCanceled

func (r *Request) IsCanceled() bool

IsCanceled checks if the job is canceled

func (*Request) MarkCanceled

func (r *Request) MarkCanceled()

MarkCanceled updates the job's status to "canceled"

func (*Request) MarkComplete

func (r *Request) MarkComplete(resp *TaskResponse)

MarkComplete sets the status of the request to "completed" and notifies via the channel.

func (*Request) Validate

func (r *Request) Validate() error

Validate checks if the request is properly structured and all tasks are valid.

type Task

type Task struct {
	ID         string   // Unique ID for the task
	Callback   Callback `json:"-"` // Exclude this field from marshaling
	Timeout    time.Duration
	RetryCount int
}

Represents a task to be executed.

func NewTask

func NewTask(id string, callback Callback) *Task

Create a new task with an ID and callback.

func (*Task) MarshalJSON

func (t *Task) MarshalJSON() ([]byte, error)

MarshalJSON is a custom marshaler for Task that excludes the Callback function.

func (*Task) UnmarshalJSON

func (t *Task) UnmarshalJSON(data []byte) error

UnmarshalJSON is a custom unmarshaler for Task.

func (*Task) Validate

func (t *Task) Validate() error

Validate checks the Task's properties for validity.

func (*Task) WithMilliSecondTimeout

func (t *Task) WithMilliSecondTimeout(d int) *Task

Set timeout in milliseconds for a task.

func (*Task) WithRetry

func (t *Task) WithRetry(count int) *Task

Set retry count for a task in case of failure.

func (*Task) WithSecondTimeout

func (t *Task) WithSecondTimeout(d int) *Task

Set timeout in seconds for a task.

type TaskResponse

type TaskResponse struct {
	Data  interface{}
	Error error
}

Response structure for a task execution.

Jump to

Keyboard shortcuts

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