-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor(runners): extract jobs to separate entity
- Loading branch information
Showing
16 changed files
with
447 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
swagger: '3.0' | ||
info: | ||
title: SEMAPHORE | ||
description: Semaphore Runner API | ||
version: "2.2.0" | ||
|
||
host: localhost:3000 | ||
|
||
consumes: | ||
- application/json | ||
produces: | ||
- application/json | ||
- text/plain; charset=utf-8 | ||
|
||
tags: | ||
- name: authentication | ||
description: Authentication, Logout & API Tokens | ||
- name: project | ||
description: Everything related to a project | ||
- name: user | ||
description: User-related API | ||
|
||
schemes: | ||
- http | ||
- https | ||
|
||
basePath: /api/runners | ||
|
||
definitions: | ||
|
||
paths: | ||
/register: | ||
post: | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
required: | ||
- registrationToken | ||
properties: | ||
registrationToken: { type: string } | ||
responses: | ||
200: | ||
description: API Token | ||
|
||
/unregister: | ||
post: | ||
|
||
/status: | ||
put: | ||
|
||
/jobs: | ||
get: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package runners | ||
|
||
import ( | ||
"github.com/ansible-semaphore/semaphore/api/helpers" | ||
"github.com/ansible-semaphore/semaphore/db" | ||
"github.com/ansible-semaphore/semaphore/util" | ||
"github.com/gorilla/mux" | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
func RunnerRoute() *mux.Router { | ||
r := mux.NewRouter() | ||
|
||
webPath := "/" | ||
if util.WebHostURL != nil { | ||
webPath = util.WebHostURL.Path | ||
if !strings.HasSuffix(webPath, "/") { | ||
webPath += "/" | ||
} | ||
} | ||
|
||
pingRouter := r.Path(webPath + "api/runners/register").Subrouter() | ||
|
||
pingRouter.Methods("POST", "HEAD").HandlerFunc(registerRunner) | ||
|
||
return r | ||
} | ||
|
||
func registerRunner(w http.ResponseWriter, r *http.Request) { | ||
var register struct { | ||
RegistrationToken string `json:"registration_token" binding:"required"` | ||
} | ||
|
||
if !helpers.Bind(w, r, ®ister) { | ||
return | ||
} | ||
|
||
if register.RegistrationToken != util.Config.RegistrationToken { | ||
return | ||
} | ||
|
||
runner, err := helpers.Store(r).CreateRunner(db.Runner{ | ||
State: db.RunnerActive, | ||
}) | ||
|
||
if err != nil { | ||
return | ||
} | ||
|
||
helpers.WriteJSON(w, http.StatusOK, runner) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/ansible-semaphore/semaphore/services/runners" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(runnerCmd) | ||
} | ||
|
||
func runRunner() { | ||
|
||
taskPool := runners.JobPool{} | ||
|
||
go taskPool.Run() | ||
} | ||
|
||
var runnerCmd = &cobra.Command{ | ||
Use: "runner", | ||
Short: "Run in runner mode", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
runRunner() | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package db | ||
|
||
type RunnerState string | ||
|
||
const ( | ||
RunnerOffline RunnerState = "offline" | ||
RunnerActive RunnerState = "active" | ||
) | ||
|
||
type Runner struct { | ||
ID int `db:"id" json:"-"` | ||
Token string `db:"token" json:"token"` | ||
ProjectID *int `db:"project_id" json:"project_id"` | ||
State RunnerState `db:"state" json:"state"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package bolt | ||
|
||
import "github.com/ansible-semaphore/semaphore/db" | ||
|
||
func (d *BoltDb) GetRunner(projectID int, runnerID int) (runner db.Runner, err error) { | ||
return | ||
} | ||
|
||
func (d *BoltDb) GetRunners(projectID int) (runners []db.Runner, err error) { | ||
return | ||
} | ||
|
||
func (d *BoltDb) DeleteRunner(projectID int, runnerID int) (err error) { | ||
return | ||
} | ||
|
||
func (d *BoltDb) GetGlobalRunner(runnerID int) (runner db.Runner, err error) { | ||
return | ||
} | ||
|
||
func (d *BoltDb) GetGlobalRunners() (runners []db.Runner, err error) { | ||
return | ||
} | ||
|
||
func (d *BoltDb) DeleteGlobalRunner(runnerID int) (err error) { | ||
return | ||
} | ||
|
||
func (d *BoltDb) UpdateRunner(runner db.Runner) (err error) { | ||
return | ||
} | ||
|
||
func (d *BoltDb) CreateRunner(runner db.Runner) (newRunner db.Runner, err error) { | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package sql | ||
|
||
import "github.com/ansible-semaphore/semaphore/db" | ||
|
||
func (d *SqlDb) GetRunner(projectID int, runnerID int) (runner db.Runner, err error) { | ||
return | ||
} | ||
|
||
func (d *SqlDb) GetRunners(projectID int) (runners []db.Runner, err error) { | ||
return | ||
} | ||
|
||
func (d *SqlDb) DeleteRunner(projectID int, runnerID int) (err error) { | ||
return | ||
} | ||
|
||
func (d *SqlDb) GetGlobalRunner(runnerID int) (runner db.Runner, err error) { | ||
return | ||
} | ||
|
||
func (d *SqlDb) GetGlobalRunners() (runners []db.Runner, err error) { | ||
return | ||
} | ||
|
||
func (d *SqlDb) DeleteGlobalRunner(runnerID int) (err error) { | ||
return | ||
} | ||
|
||
func (d *SqlDb) UpdateRunner(runner db.Runner) (err error) { | ||
return | ||
} | ||
|
||
func (d *SqlDb) CreateRunner(runner db.Runner) (newRunner db.Runner, err error) { | ||
return | ||
} |
Oops, something went wrong.