services

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package services provides business logic implementation for the API

Package services provides business logic implementation for the API

Index

Constants

View Source
const DefaultBackoff = time.Second

DefaultBackoff is the default backoff time for the worker

Variables

View Source
var (
	ErrUserNotFound     = errors.New("user not found")
	ErrUserCreateFailed = errors.New("failed to create user")
)

User service errors

Functions

This section is empty.

Types

type Instance

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

Instance provides business logic for instance operations

func NewInstanceService

func NewInstanceService(repo *repos.InstanceRepository, taskService *Task, projectService *Project) *Instance

NewInstanceService creates a new instance service instance

func (*Instance) CreateInstance

func (s *Instance) CreateInstance(ctx context.Context, instances []types.InstanceRequest) error

CreateInstance creates a new instance and a new task to track the instance creation in the DB.

func (*Instance) GetByID added in v0.0.2

func (s *Instance) GetByID(ctx context.Context, ownerID uint, instanceID uint) (*models.Instance, error)

GetByID retrieves an instance by ID

func (*Instance) GetByName added in v0.0.2

func (s *Instance) GetByName(ctx context.Context, ownerID uint, name string) (*models.Instance, error)

GetByName retrieves an instance by name

func (*Instance) GetByProjectIDAndInstanceNames added in v0.0.2

func (s *Instance) GetByProjectIDAndInstanceNames(ctx context.Context, ownerID uint, projectID uint, names []string) ([]models.Instance, error)

GetByProjectIDAndInstanceNames retrieves instances by project ID and instance names

func (*Instance) GetInstance

func (s *Instance) GetInstance(ctx context.Context, ownerID, id uint) (*models.Instance, error)

GetInstance retrieves an instance by ID

func (*Instance) ListInstances

func (s *Instance) ListInstances(ctx context.Context, ownerID uint, opts *models.ListOptions) ([]models.Instance, error)

ListInstances retrieves a paginated list of instances

func (*Instance) MarkAsTerminated added in v0.0.2

func (s *Instance) MarkAsTerminated(ctx context.Context, ownerID, instanceID uint) error

MarkAsTerminated marks an instance as terminated

func (*Instance) Terminate

func (s *Instance) Terminate(ctx context.Context, ownerID uint, projectName string, instanceNames []string) error

Terminate handles the termination of instances for a given project name and instance names.

func (*Instance) UpdateByID added in v0.0.2

func (s *Instance) UpdateByID(ctx context.Context, ownerID uint, instanceID uint, instance *models.Instance) error

UpdateByID updates an instance by ID

func (*Instance) UpdateByName added in v0.0.2

func (s *Instance) UpdateByName(ctx context.Context, ownerID uint, name string, instance *models.Instance) error

UpdateByName updates an instance by name

type Project

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

Project handles project-related operations

func NewProjectService

func NewProjectService(repo *repos.ProjectRepository) *Project

NewProjectService creates a new instance of ProjectService

func (*Project) Create

func (s *Project) Create(ctx context.Context, project *models.Project) error

Create creates a new project

func (*Project) Delete

func (s *Project) Delete(ctx context.Context, ownerID uint, name string) error

Delete deletes a project by name

func (*Project) GetByName

func (s *Project) GetByName(ctx context.Context, ownerID uint, name string) (*models.Project, error)

GetByName retrieves a project by name

func (*Project) List

func (s *Project) List(ctx context.Context, ownerID uint, opts *models.ListOptions) ([]models.Project, error)

List retrieves all projects with pagination

func (*Project) ListInstances

func (s *Project) ListInstances(ctx context.Context, ownerID uint, projectName string, opts *models.ListOptions) ([]models.Instance, error)

ListInstances retrieves all instances for a specific project

type Task

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

Task handles task-related operations

func NewTaskService

func NewTaskService(repo *repos.TaskRepository, projectService *Project) *Task

NewTaskService creates a new instance of TaskService

func (*Task) AddLogs

func (s *Task) AddLogs(ctx context.Context, ownerID uint, taskID uint, logs string) error

AddLogs appends logs to a task

func (*Task) CompleteTask

func (s *Task) CompleteTask(ctx context.Context, ownerID uint, taskID uint, result json.RawMessage) error

CompleteTask marks a task as completed and sends webhook if configured

func (*Task) Create

func (s *Task) Create(ctx context.Context, task *models.Task) error

Create creates a new task

func (*Task) CreateBatch added in v0.0.2

func (s *Task) CreateBatch(ctx context.Context, tasks []*models.Task) error

CreateBatch creates a batch of tasks

func (*Task) GetByID

func (s *Task) GetByID(ctx context.Context, ownerID uint, taskID uint) (*models.Task, error)

GetByID retrieves a task by ID

func (*Task) GetByName

func (s *Task) GetByName(ctx context.Context, ownerID uint, taskName string) (*models.Task, error)

GetByName retrieves a task by name

func (*Task) GetSchedulableTasks

func (s *Task) GetSchedulableTasks(ctx context.Context, limit int) ([]models.Task, error)

GetSchedulableTasks retrieves tasks ready for the worker to process.

func (*Task) ListByProject

func (s *Task) ListByProject(ctx context.Context, ownerID uint, projectName string, opts *models.ListOptions) ([]models.Task, error)

ListByProject retrieves all tasks for a specific project with pagination

func (*Task) SetError

func (s *Task) SetError(ctx context.Context, ownerID uint, taskID uint, errMsg string) error

SetError updates a task with error information

func (*Task) SetResult

func (s *Task) SetResult(ctx context.Context, ownerID uint, taskID uint, result json.RawMessage) error

SetResult updates a task with results data

func (*Task) Update

func (s *Task) Update(ctx context.Context, ownerID uint, task *models.Task) error

Update updates an existing task.

func (*Task) UpdateFailed added in v0.0.2

func (s *Task) UpdateFailed(ctx context.Context, task *models.Task, errMsg, logMsg string) error

UpdateFailed updates a task as failed

func (*Task) UpdateStatus

func (s *Task) UpdateStatus(ctx context.Context, ownerID uint, taskID uint, status models.TaskStatus) error

UpdateStatus updates the status of a task

func (*Task) UpdateStatusByName

func (s *Task) UpdateStatusByName(ctx context.Context, ownerID uint, taskName string, status models.TaskStatus) error

UpdateStatusByName updates the status of a task by name

type User

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

User provides business logic for user operations

func NewUserService

func NewUserService(repo *repos.UserRepository) *User

NewUserService creates a new user service instance

func (User) CreateUser

func (s User) CreateUser(ctx context.Context, user *models.User) (uint, error)

CreateUser creates a new user

func (User) DeleteUser

func (s User) DeleteUser(ctx context.Context, userID uint) error

DeleteUser deletes a user

func (User) GetAllUsers

func (s User) GetAllUsers(ctx context.Context, opts *models.ListOptions) ([]models.User, error)

GetAllUsers retrieves all users

func (User) GetUserByID

func (s User) GetUserByID(ctx context.Context, userID uint) (*models.User, error)

GetUserByID retrieves a user by id

func (User) GetUserByUsername

func (s User) GetUserByUsername(ctx context.Context, username string) (*models.User, error)

GetUserByUsername retrieves a user by username

type Worker added in v0.0.2

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

Worker is a struct that contains the worker's dependencies

func NewWorker added in v0.0.2

func NewWorker(instanceService *Instance, projectService *Project, taskService *Task, userService *User, backoff time.Duration) *Worker

NewWorker creates a new Worker

func (*Worker) LaunchWorker added in v0.0.2

func (w *Worker) LaunchWorker(ctx context.Context, wg *sync.WaitGroup)

LaunchWorker launches a goroutine that will initialize the worker and execute tasks

Jump to

Keyboard shortcuts

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