summaryrefslogtreecommitdiffstats
path: root/routers/private/manager.go
blob: 1238ff2d285dbe2289572ba76358dead3dc3143b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2020 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package private

import (
	"net/http"

	"code.gitea.io/gitea/modules/graceful"
	"code.gitea.io/gitea/modules/log"
	"code.gitea.io/gitea/modules/private"
	"code.gitea.io/gitea/modules/queue"

	"gitea.com/macaron/macaron"
)

// FlushQueues flushes all the Queues
func FlushQueues(ctx *macaron.Context, opts private.FlushOptions) {
	if opts.NonBlocking {
		// Save the hammer ctx here - as a new one is created each time you call this.
		baseCtx := graceful.GetManager().HammerContext()
		go func() {
			err := queue.GetManager().FlushAll(baseCtx, opts.Timeout)
			if err != nil {
				log.Error("Flushing request timed-out with error: %v", err)
			}
		}()
		ctx.JSON(http.StatusAccepted, map[string]interface{}{
			"err": "Flushing",
		})
		return
	}
	err := queue.GetManager().FlushAll(ctx.Req.Request.Context(), opts.Timeout)
	if err != nil {
		ctx.JSON(http.StatusRequestTimeout, map[string]interface{}{
			"err": err,
		})
	}
	ctx.PlainText(http.StatusOK, []byte("success"))
}