Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

manager.go 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package private
  5. import (
  6. "net/http"
  7. "code.gitea.io/gitea/modules/graceful"
  8. "code.gitea.io/gitea/modules/log"
  9. "code.gitea.io/gitea/modules/private"
  10. "code.gitea.io/gitea/modules/queue"
  11. "gitea.com/macaron/macaron"
  12. )
  13. // FlushQueues flushes all the Queues
  14. func FlushQueues(ctx *macaron.Context, opts private.FlushOptions) {
  15. if opts.NonBlocking {
  16. // Save the hammer ctx here - as a new one is created each time you call this.
  17. baseCtx := graceful.GetManager().HammerContext()
  18. go func() {
  19. err := queue.GetManager().FlushAll(baseCtx, opts.Timeout)
  20. if err != nil {
  21. log.Error("Flushing request timed-out with error: %v", err)
  22. }
  23. }()
  24. ctx.JSON(http.StatusAccepted, map[string]interface{}{
  25. "err": "Flushing",
  26. })
  27. return
  28. }
  29. err := queue.GetManager().FlushAll(ctx.Req.Request.Context(), opts.Timeout)
  30. if err != nil {
  31. ctx.JSON(http.StatusRequestTimeout, map[string]interface{}{
  32. "err": err,
  33. })
  34. }
  35. ctx.PlainText(http.StatusOK, []byte("success"))
  36. }