Fix runner logic and add git clone step
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.ohea.xyz/cursorius/runner/config"
|
||||
"git.ohea.xyz/cursorius/runner/runner"
|
||||
"github.com/op/go-logging"
|
||||
"nhooyr.io/websocket"
|
||||
"nhooyr.io/websocket/wsjson"
|
||||
@@ -19,11 +20,6 @@ type Register struct {
|
||||
Tags []string
|
||||
}
|
||||
|
||||
type Job struct {
|
||||
URL *string
|
||||
Folder *string
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
var format = logging.MustStringFormatter(
|
||||
@@ -60,26 +56,31 @@ func main() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
||||
defer cancel()
|
||||
|
||||
c, _, err := websocket.Dial(ctx, connectString, nil)
|
||||
conn, _, err := websocket.Dial(ctx, connectString, nil)
|
||||
if err != nil {
|
||||
log.Fatalf("Could not connect to server at \"%v\", %v", connectString, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer c.Close(websocket.StatusInternalError, "the sky is falling")
|
||||
defer conn.Close(websocket.StatusInternalError, "the sky is falling")
|
||||
|
||||
err = wsjson.Write(ctx, c, registrationData)
|
||||
err = wsjson.Write(ctx, conn, registrationData)
|
||||
if err != nil {
|
||||
log.Fatalf("Could not send registration information to server: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
for {
|
||||
var job Job
|
||||
err = wsjson.Read(ctx, c, &job)
|
||||
var job runner.Job
|
||||
err = wsjson.Read(ctx, conn, &job)
|
||||
if err != nil {
|
||||
log.Fatalf("Could not receive from connection: %v", err)
|
||||
continue
|
||||
}
|
||||
log.Infof("Received job from server: %v", *job.URL)
|
||||
log.Infof("Received job from server: id: %v, URL: %v", job.Id, job.URL)
|
||||
|
||||
err = runner.RunJob(job, configData.Config.WorkingDir)
|
||||
if err != nil {
|
||||
log.Errorf("Could not run job: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user