Skip to content

Commit

Permalink
Consider existing Job
Browse files Browse the repository at this point in the history
  • Loading branch information
vcastellm committed Apr 1, 2024
1 parent d46947b commit a2face7
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions dkron/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,17 @@ func (h *HTTPTransport) jobCreateOrUpdateHandler(c *gin.Context) {
Concurrency: ConcurrencyAllow,
}

// Parse values from JSON
if err := c.BindJSON(&job); err != nil {
_, _ = c.Writer.WriteString(fmt.Sprintf("Unable to parse payload: %s.", err))
h.logger.Error(err)
return
// Check if the job is already in the context set by the middleware
val, exists := c.Get("job")
if exists {
job = val.(Job)
} else {
// Parse values from JSON
if err := c.BindJSON(&job); err != nil {
_, _ = c.Writer.WriteString(fmt.Sprintf("Unable to parse payload: %s.", err))
h.logger.Error(err)
return
}
}

// Validate job
Expand Down

0 comments on commit a2face7

Please sign in to comment.