mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-13 06:40:41 +00:00
Use global async flag as fallback on per-request flag
This way, if no pre-request flag is specified, the globally configured default is used.
This commit is contained in:
+13
-5
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/aptly-dev/aptly/aptly"
|
"github.com/aptly-dev/aptly/aptly"
|
||||||
@@ -111,17 +112,24 @@ func runTaskInBackground(name string, resources []string, proc task.Process) (ta
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func truthy(value string) bool {
|
func truthy(value interface{}) bool {
|
||||||
switch strings.ToLower(value) {
|
switch value.(type) {
|
||||||
case "y", "yes", "t", "true":
|
case string:
|
||||||
return true
|
switch strings.ToLower(value.(string)) {
|
||||||
|
case "y", "yes", "t", "true", "1":
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
case int:
|
||||||
|
return value.(int) == 1
|
||||||
|
case bool:
|
||||||
|
return value.(bool)
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func maybeRunTaskInBackground(c *gin.Context, name string, resources []string, proc task.Process) {
|
func maybeRunTaskInBackground(c *gin.Context, name string, resources []string, proc task.Process) {
|
||||||
// Run this task in background if configured globally or per-request
|
// Run this task in background if configured globally or per-request
|
||||||
background := context.Config().AsyncAPI || truthy(c.Query("_async"))
|
background := truthy(c.DefaultQuery("_async", strconv.FormatBool(context.Config().AsyncAPI)))
|
||||||
if background {
|
if background {
|
||||||
log.Println("Executing task asynchronously")
|
log.Println("Executing task asynchronously")
|
||||||
task, conflictErr := runTaskInBackground(name, resources, proc)
|
task, conflictErr := runTaskInBackground(name, resources, proc)
|
||||||
|
|||||||
@@ -91,3 +91,21 @@ func (s *ApiSuite) TestGetVersion(c *C) {
|
|||||||
c.Check(response.Code, Equals, 200)
|
c.Check(response.Code, Equals, 200)
|
||||||
c.Check(response.Body.String(), Matches, ".*Version.*")
|
c.Check(response.Body.String(), Matches, ".*Version.*")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ApiSuite) TestTruthy(c *C) {
|
||||||
|
c.Check(truthy("y"), Equals, true)
|
||||||
|
c.Check(truthy("yes"), Equals, true)
|
||||||
|
c.Check(truthy("t"), Equals, true)
|
||||||
|
c.Check(truthy("true"), Equals, true)
|
||||||
|
c.Check(truthy("1"), Equals, true)
|
||||||
|
c.Check(truthy(true), Equals, true)
|
||||||
|
c.Check(truthy(1), Equals, true)
|
||||||
|
|
||||||
|
c.Check(truthy("no"), Equals, false)
|
||||||
|
c.Check(truthy("foobar"), Equals, false)
|
||||||
|
c.Check(truthy(0), Equals, false)
|
||||||
|
c.Check(truthy(-1), Equals, false)
|
||||||
|
c.Check(truthy(false), Equals, false)
|
||||||
|
c.Check(truthy(nil), Equals, false)
|
||||||
|
c.Check(truthy(gin.H{}), Equals, false)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user