services

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 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

This section is empty.

Variables

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

User service errors

Functions

func LaunchWorker

func LaunchWorker(ctx context.Context, wg *sync.WaitGroup, taskService *Task)

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

Types

type Infrastructure

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

Infrastructure represents the infrastructure management system. It coordinates the creation and deletion of cloud resources across different providers and handles the provisioning of those resources using configuration management tools.

func NewInfrastructure

func NewInfrastructure(req *types.InstancesRequest) (*Infrastructure, error)

NewInfrastructure creates a new infrastructure instance with the specified configuration. It initializes the appropriate cloud provider and provisioner based on the request.

Parameters:

  • req: The job request containing the infrastructure configuration

Returns:

  • *Infrastructure: A configured infrastructure manager
  • error: Any error that occurred during initialization

func (*Infrastructure) Execute

func (i *Infrastructure) Execute() (interface{}, error)

Execute performs the requested infrastructure operation (create or delete). For creation, it spawns the requested number of instances with the specified configuration. For deletion, it removes the specified instances from the cloud provider.

Returns:

  • interface{}: The result of the operation
  • For creation: []InstanceInfo containing details of created instances
  • For deletion: map[string]interface{} with operation status and deleted instances
  • error: Any error that occurred during execution

func (*Infrastructure) RunProvisioning

func (i *Infrastructure) RunProvisioning(instances []types.InstanceInfo) error

RunProvisioning applies Ansible configuration to all instances

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, ownerID uint, projectName string, instances []types.InstanceRequest) (string, error)

CreateInstance creates a new task to track instance creation and starts the process.

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) Terminate

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

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

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) 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) 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

Jump to

Keyboard shortcuts

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