mirror of
https://github.com/semaphoreui/semaphore.git
synced 2024-11-25 06:15:56 +01:00
67a29f763b
- Define extra (environment) vars to tasks - Able to create custom ansible jobs by defining parameters (infinite usabilities for user here) - Log output to db - Debug tasks - Ssh key for accessing inventory (separate from the key to access inventory api) -
36 lines
786 B
Go
36 lines
786 B
Go
package tasks
|
|
|
|
import (
|
|
"bufio"
|
|
"os/exec"
|
|
|
|
"github.com/ansible-semaphore/semaphore/database"
|
|
"github.com/ansible-semaphore/semaphore/routes/sockets"
|
|
)
|
|
|
|
func (t *task) log(msg string) {
|
|
// TODO: broadcast to a set of users listening to this project
|
|
sockets.Broadcast([]byte(msg))
|
|
|
|
go func() {
|
|
_, err := database.Mysql.Exec("insert into task__output set task_id=?, output=?", t.task.ID, msg)
|
|
if err != nil {
|
|
sockets.Broadcast([]byte("Error logging task output" + err.Error()))
|
|
}
|
|
}()
|
|
}
|
|
|
|
func (t *task) logPipe(scanner *bufio.Scanner) {
|
|
for scanner.Scan() {
|
|
t.log(scanner.Text())
|
|
}
|
|
}
|
|
|
|
func (t *task) logCmd(cmd *exec.Cmd) {
|
|
stderr, _ := cmd.StderrPipe()
|
|
stdout, _ := cmd.StdoutPipe()
|
|
|
|
go t.logPipe(bufio.NewScanner(stderr))
|
|
go t.logPipe(bufio.NewScanner(stdout))
|
|
}
|