Go API Documentation

github.com/semaphoreui/semaphore/services/tasks

No package summary is available.

Package

Files: 7. Third party imports: 1. Imports from organisation: 0. Tests: 0. Benchmarks: 0.

Constants

Vars

Types

Alert

Alert represents an alert that will be templated and sent to the appropriate service

Field name Field type Comment
Name

string

No comment on field.
Author

string

No comment on field.
Color

string

No comment on field.
Task

alertTask

No comment on field.
Chat

alertChat

No comment on field.

EventType

This type doesn't have documentation.

Field name Field type Comment
type

uint

No comment on field.

Job

This type doesn't have documentation.

Field name Field type Comment
type

any

No comment on field.

LocalJob

This type doesn't have documentation.

Field name Field type Comment
Task

db.Task

No comment on field.
Template

db.Template

No comment on field.
Inventory

db.Inventory

No comment on field.
Repository

db.Repository

No comment on field.
Environment

db.Environment

No comment on field.
Secret

string

No comment on field.
Logger

task_logger.Logger

No comment on field.
App

db_lib.LocalApp

No comment on field.
killed

bool

No comment on field.
Process

*os.Process

No comment on field.
sshKeyInstallation

db.AccessKeyInstallation

No comment on field.
becomeKeyInstallation

db.AccessKeyInstallation

No comment on field.
vaultFileInstallations

map[string]db.AccessKeyInstallation

No comment on field.

PoolEvent

This type doesn't have documentation.

Field name Field type Comment
eventType

EventType

No comment on field.
task

*TaskRunner

No comment on field.

RemoteJob

This type doesn't have documentation.

Field name Field type Comment
RunnerTag

*string

No comment on field.
Task

db.Task

No comment on field.
taskPool

*TaskPool

No comment on field.
killed

bool

No comment on field.

TaskPool

This type doesn't have documentation.

Field name Field type Comment
Queue

[]*TaskRunner

Queue contains list of tasks in status TaskWaitingStatus.

register

chan *TaskRunner

register channel used to put tasks to queue.

activeProj

map[int]map[int]*TaskRunner

activeProj ???

RunningTasks

map[int]*TaskRunner

RunningTasks contains tasks with status TaskRunningStatus. Map key is a task ID.

logger

chan logRecord

logger channel used to putting log records to database.

store

db.Store

No comment on field.
queueEvents

chan PoolEvent

No comment on field.
aliases

map[string]*TaskRunner

No comment on field.

TaskRunner

This type doesn't have documentation.

Field name Field type Comment
Task

db.Task

No comment on field.
Template

db.Template

No comment on field.
Inventory

db.Inventory

No comment on field.
Repository

db.Repository

No comment on field.
Environment

db.Environment

No comment on field.
currentStage

*db.TaskStage

No comment on field.
currentOutput

*db.TaskOutput

No comment on field.
currentState

any

No comment on field.
users

[]int

No comment on field.
alert

bool

No comment on field.
alertChat

*string

No comment on field.
pool

*TaskPool

No comment on field.
job

Job

job executes Ansible and returns stdout to Semaphore logs

RunnerID

int

No comment on field.
Username

string

No comment on field.
IncomingVersion

*string

No comment on field.
statusListeners

[]task_logger.StatusListener

No comment on field.
logListeners

[]task_logger.LogListener

No comment on field.
Alias

string

Alias uses if task require an alias for run. For example, terraform task require an alias for run.

logWG

sync.WaitGroup

No comment on field.

alertChat

This type doesn't have documentation.

Field name Field type Comment
ID

string

No comment on field.

alertTask

This type doesn't have documentation.

Field name Field type Comment
ID

string

No comment on field.
URL

string

No comment on field.
Result

string

No comment on field.
Desc

string

No comment on field.
Version

string

No comment on field.

logRecord

This type doesn't have documentation.

Field name Field type Comment
task

*TaskRunner

No comment on field.
output

string

No comment on field.
time

time.Time

No comment on field.

runnerWebhookPayload

This type doesn't have documentation.

Field name Field type Comment
Action

string

No comment on field.
ProjectID

int

No comment on field.
TaskID

int

No comment on field.
TemplateID

int

No comment on field.
RunnerID

int

No comment on field.

Functions

func CreateTaskPool

func (*LocalJob) IsKilled

func (*LocalJob) Kill

func (*LocalJob) Log

func (*LocalJob) Run

Uses: db.AccessKeySSH, db.AppAnsible, db.AppTerraform, db.AppTerragrunt, db.AppTofu, db.TemplateBuild, db.TemplateTask, fmt.Sprintf, os.Process, util.GetPublicAliasURL.

func (*LocalJob) SetCommit

func (*LocalJob) SetStatus

func (*RemoteJob) IsKilled

func (*RemoteJob) Kill

func (*RemoteJob) Run

Uses: db.Runner, db.StoreSession, fmt.Errorf, time.Sleep, tz.Now, util.Config.

func (*TaskPool) AddTask

AddTask creates and queues a new task for execution in the task pool.

Parameters:

  • taskObj: The task object with initial configuration
  • userID: Optional ID of the user initiating the task
  • username: Username of the user initiating the task
  • projectID: ID of the project this task belongs to
  • needAlias: Whether to generate a unique alias for the task

The method:

  • Sets initial task properties (created time, waiting status, etc.)
  • Validates the task against its template
  • For build templates, calculates the next version number
  • Creates the task record in the database
  • Sets up appropriate job handler (local or remote)
  • Queues the task for execution

Returns:

  • The newly created task with all properties set
  • An error if task creation or validation fails

Uses: db.RetrieveQueryParams, db.TaskWithTpl, db.TemplateBuild, random.String, tz.Now, util.Config.

func (*TaskPool) ConfirmTask

Uses: fmt.Errorf.

func (*TaskPool) GetNumberOfRunningTasksOfRunner

func (*TaskPool) GetRunningTasks

func (*TaskPool) GetTask

func (*TaskPool) GetTaskByAlias

func (*TaskPool) MoveToNextStage

Uses: db.TaskStage, log.Error.

func (*TaskPool) RejectTask

Uses: fmt.Errorf.

func (*TaskPool) Run

nolint: gocyclo

Uses: db.StoreSession, db.TaskOutput, log.Debug, log.Error, log.Info, strconv.Itoa, time.NewTicker, time.Second.

func (*TaskPool) StopTask

func (*TaskRunner) AddLogListener

func (*TaskRunner) AddStatusListener

func (*TaskRunner) Log

Uses: tz.Now.

func (*TaskRunner) LogCmd

func (*TaskRunner) LogWithTime

Uses: json.Marshal, sockets.Message, util.LogPanic.

func (*TaskRunner) Logf

Uses: tz.Now.

func (*TaskRunner) LogfWithTime

Uses: fmt.Sprintf.

func (*TaskRunner) SetCommit

func (*TaskRunner) SetStatus

Uses: tz.Now.

func (*TaskRunner) WaitLog

Private functions

func callRunnerWebhook

References: bytes.NewBuffer, fmt.Errorf, http.Client, http.NewRequest, http.Request, http.Response, json.Marshal, log.Fields, log.WithFields.

func checkTmpDir

checkTmpDir checks to see if the temporary directory exists and if it does not attempts to create it

References: os.IsNotExist, os.MkdirAll, os.Stat.

func getNextBuildVersion

References: regexp.MustCompile, strconv.Atoi, strconv.Itoa, strings.HasPrefix, strings.HasSuffix.

func runTask

References: log.Info, strconv.Itoa.

func checkoutRepository

func cloneInventoryRepo

References: os.RemoveAll.

func destroyInventoryFile

References: log.Fields, log.WithError, os.IsNotExist, os.Remove.

func destroyKeys

func getCLIArgs

References: fmt.Errorf, json.Unmarshal.

func getEnvironmentENV

References: db.EnvironmentSecretEnv, fmt.Sprintf, json.Unmarshal.

func getEnvironmentExtraVars

References: db.TemplateBuild, db.TemplateTask, json.Unmarshal.

func getEnvironmentExtraVarsJSON

References: db.TemplateBuild, db.TemplateTask, json.Marshal, json.Unmarshal, maps.Copy.

func getParams

References: db.AnsibleTaskParams, db.AppAnsible, db.AppTerraform, db.AppTerragrunt, db.AppTofu, db.DefaultTaskParams, db.TerraformTaskParams.

func getPlaybookArgs

nolint: gocyclo

References: db.AccessKeyLoginPassword, db.AccessKeyNone, db.AccessKeyRole, db.AccessKeyRoleAnsibleBecomeUser, db.AccessKeyRoleAnsibleUser, db.AccessKeySSH, db.AnsibleTaskParams, db.AnsibleTemplateParams, db.EnvironmentSecretVar, db.InventoryFile, db.InventoryStatic, db.InventoryStaticYaml, fmt.Errorf, fmt.Sprintf, path.Join, strings.Join, strings.Repeat.

func getShellArgs

nolint: gocyclo

References: db.EnvironmentSecretVar, fmt.Sprintf.

func getTemplateParams

References: db.AnsibleTemplateParams, db.AppAnsible, db.AppTerraform, db.AppTerragrunt, db.AppTofu, db.TerraformTemplateParams.

func getTerraformArgs

nolint: gocyclo

References: db.EnvironmentSecretVar, db.TerraformTaskParams, fmt.Sprintf.

func installInventory

References: db.AccessKeyRoleAnsibleBecomeUser, db.AccessKeyRoleAnsibleUser, db.InventoryFile, db.InventoryStatic, db.InventoryStaticYaml.

func installStaticInventory

References: os.WriteFile.

func installVaultKeyFiles

References: db.AccessKeyInstallation, db.AccessKeyRoleAnsiblePasswordVault, db.TemplateVaultPassword, db.TemplateVaultScript.

func prepareRun

References: db.RepositoryLocal, os.Stat, strconv.Itoa, util.Config.

func tmpInventoryFilename

References: strconv.Itoa.

func tmpInventoryFullPath

References: db.InventoryStaticYaml, path.Join, util.Config.

func updateRepository

References: os.IsNotExist, os.RemoveAll.

func blocks

References: log.Error, util.Config.

func handleQueue

References: log.Info, slices.Delete, strconv.Itoa.

func onTaskRun

func onTaskStop

func alertColor

func alertInfos

References: db.TemplateTask.

func createTaskEvent

References: db.Event, db.EventTask, hooks.GetHook, log.Error, log.WithError, strconv.Itoa, strings.ToUpper, util.Config, util.TaskLogRecord.

func kill

func logPipe

References: bufio.NewScanner, log.Fields, log.WithError.

func panicOnError

References: log.Fields, util.LogPanicF.

func populateDetails

nolint: gocyclo

References: db.FillEnvironmentSecrets, db.RetrieveQueryParams, json.Marshal, json.Unmarshal.

func prepareError

References: db.ErrNotFound, errors.Is.

func run

References: db.RetrieveQueryParams, db.Task, db.TemplateFilter, db.TemplateTask, db.User, log.Fields, log.Info, log.WithError, strconv.Itoa, tz.Now.

func saveStatus

References: json.Marshal, sockets.Message, util.LogPanic.

func sendDingTalkAlert

References: bytes.NewBufferString, http.Post, strconv.Itoa, template.ParseFS, util.Config.

func sendGotifyAlert

References: bytes.NewBufferString, fmt.Sprintf, http.Post, strconv.Itoa, template.ParseFS, util.Config.

func sendMailAlert

References: bytes.NewBufferString, fmt.Sprintf, mailer.Send, strconv.Itoa, template.ParseFS, util.Config, util.LogError.

func sendMicrosoftTeamsAlert

References: bytes.NewBufferString, http.Post, strconv.Itoa, template.ParseFS, util.Config.

func sendRocketChatAlert

References: bytes.NewBufferString, http.Post, strconv.Itoa, template.ParseFS, util.Config.

func sendSlackAlert

References: bytes.NewBufferString, http.Post, strconv.Itoa, template.ParseFS, util.Config.

func sendTelegramAlert

References: bytes.NewBufferString, fmt.Sprintf, http.Post, strconv.Itoa, template.ParseFS, util.Config.

References: fmt.Sprintf, util.Config.


Tests

Files: 2. Third party imports: 0. Imports from organisation: 0. Tests: 11. Benchmarks: 0.

Test functions

TestCheckTmpDir

References: os.Chmod, os.FileMode, os.Remove, os.Stat, os.TempDir, path.Join, rand.Intn, util.RandString.

TestGetNextBuildVersion

TestGetRepoPath

References: db.AccessKey, db.AccessKeySSH, db.Inventory, db.InventoryStatic, db.Task, db.Template, util.Config, util.ConfigType.

TestGetRepoPath_whenStartsWithSlash

References: db.AccessKey, db.AccessKeySSH, db.Inventory, db.InventoryStatic, db.Task, db.Template, util.Config, util.ConfigType.

TestPopulateDetails

References: bolt.CreateTestStore, db.AccessKey, db.AccessKeyNone, db.Environment, db.Inventory, db.Project, db.Repository, db.Task, db.Template.

TestPopulateDetailsInventory

References: bolt.CreateTestStore, db.AccessKey, db.AccessKeyNone, db.Environment, db.Inventory, db.Project, db.Repository, db.Task, db.Template.

TestPopulateDetailsInventory1

References: bolt.CreateTestStore, db.AccessKey, db.AccessKeyNone, db.Environment, db.Inventory, db.Project, db.Repository, db.Task, db.Template.

TestTaskGetPlaybookArgs

References: db.AccessKey, db.AccessKeySSH, db.Inventory, db.InventoryStatic, db.Task, db.Template, strings.Join, util.Config, util.ConfigType.

TestTaskGetPlaybookArgs2

References: db.AccessKey, db.AccessKeyLoginPassword, db.Inventory, db.InventoryStatic, db.LoginPassword, db.Task, db.Template, strings.Join, util.Config, util.ConfigType.

TestTaskGetPlaybookArgs3

References: db.AccessKey, db.AccessKeyLoginPassword, db.Inventory, db.InventoryStatic, db.LoginPassword, db.Task, db.Template, strings.Join, util.Config, util.ConfigType.

TestTaskRunnerRun

References: bolt.CreateTestStore, db.StoreSession, db.Task.