service

package
v2.3.38 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTaskNotFound         = apperr.New("task_not_found", apperr.WithTextTranslate(translator.Translate{translator.RU: "Задача не найдена", translator.EN: "Task not found"}), apperr.WithCode(code.NotFound))
	ErrTaskTypeNotFound     = apperr.New("task_type_not_found", apperr.WithTextTranslate(translator.Translate{translator.RU: "Тип задачи не найден", translator.EN: "Task's type not found"}), apperr.WithCode(code.NotFound))
	ErrTaskCannotStop       = apperr.New("task_cannot_stop", apperr.WithTextTranslate(translator.Translate{translator.RU: "Невозможно остановить завершенную задачу", translator.EN: "Cannot stop a completed task"}), apperr.WithCode(code.NotFound))
	ErrTaskUnableRerun      = apperr.New("task_unable_rerun", apperr.WithTextTranslate(translator.Translate{translator.RU: "Невозможно запустить незавершенную задачу", translator.EN: "Unable to rerun an unfinished task"}), apperr.WithCode(code.NotFound))
	ErrTaskFileNotFound     = apperr.New("task_file_not_found", apperr.WithTextTranslate(translator.Translate{translator.RU: "Файл не найден", translator.EN: "File not found"}), apperr.WithCode(code.NotFound))
	ErrTaskFileStillOngoing = apperr.New("task_file_process", apperr.WithTextTranslate(translator.Translate{translator.RU: "Задача все еще выполняется", translator.EN: "The task is still ongoing"}), apperr.WithCode(code.NotFound))
	ErrTaskTypeInvalid      = apperr.New("invalid_task_type", apperr.WithTextTranslate(translator.Translate{translator.RU: "Только export задачи могут генерировать ссылки для скачивания", translator.EN: "Only export tasks can generate download links"}), apperr.WithCode(code.Aborted))
	ErrTaskStatusInvalid    = apperr.New("invalid_task_status", apperr.WithTextTranslate(translator.Translate{translator.RU: "Задача все еще находится в исполнении", translator.EN: "The task is still in progress"}), apperr.WithCode(code.Aborted))
	ErrGenerateToken        = apperr.New("token_generation_failed", apperr.WithTextTranslate(translator.Translate{translator.RU: "Не удалось сгенерировать токен", translator.EN: "Failed to generate token"}), apperr.WithCode(code.Internal))
	ErrInvalidLink          = apperr.New("invalid_link")
)

Functions

This section is empty.

Types

type Consumer

type Consumer interface {
	Export(ctx context.Context, data []byte) (*model3.Message, error)
	Import(ctx context.Context, data []byte) (*model3.Message, error)
	MassUpdate(ctx context.Context, data []byte) (*model3.Message, error)
	MassDelete(ctx context.Context, data []byte) (*model3.Message, error)
}

type Consumers

type Consumers map[string]Consumer

type ITaskService

type ITaskService interface {
	Trx(db *gorm.DB) ITaskService
	List(ctx context.Context, m *model2.Meta[model.Task]) error
	GetFull(ctx context.Context, taskID *int, statuses ...string) ([]model.Task, error)
	Update(ctx context.Context, id int, input TaskUpdateInput) error
	UpdateStatus(ctx context.Context, status string, ids ...int) error
	Create(ctx context.Context, input TaskCreateInput) (*model.Task, error)
	GetById(ctx context.Context, id int) (*model.Task, error)
	Stop(ctx context.Context, id int) error
	Rerun(ctx context.Context, id int) (*model.Task, error)
	RunTasks(ctx context.Context, statuses []string, ids ...int) error
	Download(ctx context.Context, id int) (string, error)
	GenerateDownloadToken(ctx context.Context, id int) (string, error)
	ValidateDownloadToken(ctx context.Context, token string, id int) error
}

type Queue

type Queue interface {
	Run(data runner.Data)
	Stop(id int)
}

type TaskCreateInput

type TaskCreateInput struct {
	Name string
	Type string
	Data []byte
}

type TaskService

type TaskService struct {
	// contains filtered or unexported fields
}

func NewTaskService

func NewTaskService(
	taskRepository repository.ITaskRepository,
	services Consumers,
	queue Queue,
	tokenSecret string,
) TaskService

func (TaskService) Create

func (s TaskService) Create(ctx context.Context, input TaskCreateInput) (*model.Task, error)

func (TaskService) Download

func (s TaskService) Download(ctx context.Context, id int) (string, error)

func (TaskService) GenerateDownloadToken added in v2.3.15

func (s TaskService) GenerateDownloadToken(ctx context.Context, id int) (string, error)

func (TaskService) GetById

func (s TaskService) GetById(ctx context.Context, id int) (*model.Task, error)

func (TaskService) GetFull

func (s TaskService) GetFull(ctx context.Context, taskID *int, statuses ...string) ([]model.Task, error)

func (TaskService) List

func (s TaskService) List(ctx context.Context, m *model2.Meta[model.Task]) error

func (TaskService) Rerun

func (s TaskService) Rerun(ctx context.Context, id int) (*model.Task, error)

func (TaskService) RunTasks

func (s TaskService) RunTasks(ctx context.Context, statuses []string, ids ...int) error

func (TaskService) Stop

func (s TaskService) Stop(ctx context.Context, id int) error

func (TaskService) Trx

func (s TaskService) Trx(db *gorm.DB) ITaskService

func (TaskService) Update

func (s TaskService) Update(ctx context.Context, id int, input TaskUpdateInput) error

func (TaskService) UpdateStatus

func (s TaskService) UpdateStatus(ctx context.Context, status string, ids ...int) error

func (TaskService) ValidateDownloadToken added in v2.3.15

func (s TaskService) ValidateDownloadToken(ctx context.Context, tokenString string, id int) error

type TaskUpdateInput

type TaskUpdateInput struct {
	Status *string
	Output *model3.Message
}

Jump to

Keyboard shortcuts

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