Documentation
¶
Overview ¶
Package services provides business logic implementation for the API
Package services provides business logic implementation for the API
Index ¶
- Variables
- func LaunchWorker(ctx context.Context, wg *sync.WaitGroup, taskService *Task)
- type Infrastructure
- type Instance
- func (s *Instance) CreateInstance(ctx context.Context, ownerID uint, projectName string, ...) (string, error)
- func (s *Instance) GetInstance(ctx context.Context, ownerID, id uint) (*models.Instance, error)
- func (s *Instance) ListInstances(ctx context.Context, ownerID uint, opts *models.ListOptions) ([]models.Instance, error)
- func (s *Instance) Terminate(ctx context.Context, ownerID uint, projectName string, instanceNames []string) (taskName string, err error)
- type Project
- func (s *Project) Create(ctx context.Context, project *models.Project) error
- func (s *Project) Delete(ctx context.Context, ownerID uint, name string) error
- func (s *Project) GetByName(ctx context.Context, ownerID uint, name string) (*models.Project, error)
- func (s *Project) List(ctx context.Context, ownerID uint, opts *models.ListOptions) ([]models.Project, error)
- func (s *Project) ListInstances(ctx context.Context, ownerID uint, projectName string, ...) ([]models.Instance, error)
- type Task
- func (s *Task) AddLogs(ctx context.Context, ownerID uint, taskID uint, logs string) error
- func (s *Task) CompleteTask(ctx context.Context, ownerID uint, taskID uint, result json.RawMessage) error
- func (s *Task) Create(ctx context.Context, task *models.Task) error
- func (s *Task) GetByID(ctx context.Context, ownerID uint, taskID uint) (*models.Task, error)
- func (s *Task) GetByName(ctx context.Context, ownerID uint, taskName string) (*models.Task, error)
- func (s *Task) GetSchedulableTasks(ctx context.Context, limit int) ([]models.Task, error)
- func (s *Task) ListByProject(ctx context.Context, ownerID uint, projectName string, ...) ([]models.Task, error)
- func (s *Task) SetError(ctx context.Context, ownerID uint, taskID uint, errMsg string) error
- func (s *Task) SetResult(ctx context.Context, ownerID uint, taskID uint, result json.RawMessage) error
- func (s *Task) Update(ctx context.Context, ownerID uint, task *models.Task) error
- func (s *Task) UpdateStatus(ctx context.Context, ownerID uint, taskID uint, status models.TaskStatus) error
- func (s *Task) UpdateStatusByName(ctx context.Context, ownerID uint, taskName string, status models.TaskStatus) error
- type User
- func (s User) CreateUser(ctx context.Context, user *models.User) (uint, error)
- func (s User) DeleteUser(ctx context.Context, userID uint) error
- func (s User) GetAllUsers(ctx context.Context, opts *models.ListOptions) ([]models.User, error)
- func (s User) GetUserByID(ctx context.Context, userID uint) (*models.User, error)
- func (s User) GetUserByUsername(ctx context.Context, username string) (*models.User, error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrUserNotFound = errors.New("user not found") ErrUserCreateFailed = errors.New("failed to create user") )
User service errors
Functions ¶
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 ¶
GetInstance retrieves an instance by ID
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) GetByName ¶
func (s *Project) GetByName(ctx context.Context, ownerID uint, name string) (*models.Project, error)
GetByName retrieves a project by name
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) 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) GetSchedulableTasks ¶
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) 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) 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 ¶
CreateUser creates a new user
func (User) DeleteUser ¶
DeleteUser deletes a user
func (User) GetAllUsers ¶
GetAllUsers retrieves all users
func (User) GetUserByID ¶
GetUserByID retrieves a user by id