Skip to content

Commit

Permalink
Merge pull request #3067 from bomoko/fix/workflows-task-queue-early-exit
Browse files Browse the repository at this point in the history
  • Loading branch information
tobybellwood authored Mar 16, 2022
2 parents a4cbda3 + 4a59b62 commit 2560087
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions services/workflows/internal/handler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"log"
"net/http"
"time"

//"github.com/uselagoon/lagoon/services/actions-handler/internal/lagoon"
//lclient "github.com/uselagoon/lagoon/services/actions-handler/internal/lagoon/client"
//"github.com/uselagoon/lagoon/services/actions-handler/internal/lagoon/jwt"
Expand Down Expand Up @@ -172,14 +171,19 @@ func processingIncomingMessageQueueFactory(h *Messaging) func(mq.Message) {
incoming := &LagoonLog{}
err := json.Unmarshal(message.Body(), incoming)
if err != nil {
fmt.Println("could not unmarshall")
log.Println("could not unmarshall")
message.Ack(false)
return
}


//Ahhh, the issue is that there is no environment name passed thought ...
environmentName := incoming.Meta.Environment
environmentIdentifier := fmt.Sprintf("%v", incoming.Meta.EnvironmentID)
if incoming.Meta.Environment != "" {
environmentIdentifier = fmt.Sprintf("%v:%v", incoming.Meta.Environment, incoming.Meta.EnvironmentID)
}

if incoming.Meta.ProjectID != nil && incoming.Meta.EnvironmentID != nil {
fmt.Println("Connecting to " + h.LagoonAPI.Endpoint)
log.Println("Connecting to " + h.LagoonAPI.Endpoint)
client := graphql.NewClient(h.LagoonAPI.Endpoint,
&http.Client{Transport: &authedTransport{wrapped: http.DefaultTransport, h: h}})
projectId := int(*incoming.Meta.ProjectID)
Expand All @@ -191,18 +195,15 @@ func processingIncomingMessageQueueFactory(h *Messaging) func(mq.Message) {
for _, wf := range environmentWorkflows {
if lagoonclient.IsEventOfType(incoming.Event, wf.AdvancedTaskDetails) {
log.Printf("Found event of type %v for project:%v and environment %v - invoking.\n",
incoming.Event, projectId, environmentName)
incoming.Event, projectId, environmentIdentifier)
result, err := lagoonclient.InvokeWorkflowOnEnvironment(context.TODO(), client, wf.EnvironmentId, wf.AdvancedTaskId)
if err != nil {
log.Println(err)
//TODO: do we need some kind of retry logic here?
message.Ack(false) // ack to remove from queue
return
log.Println(fmt.Sprintf("Invocation error of %v for project:%v and environment %v - %v.\n", incoming.Event, projectId, environmentIdentifier, err))
} else {
log.Printf("Invocation result of %v for project:%v and environment %v - %v.\n",
incoming.Event, projectId, environmentIdentifier, result)
}
log.Printf("Invocation result of %v for project:%v and environment %v - %v.\n",
incoming.Event, projectId, environmentName, result)
}

}
}
message.Ack(false) // ack to remove from queue
Expand Down

0 comments on commit 2560087

Please sign in to comment.