Skip to content

Commit 8866235

Browse files
committed
Wire in UI for pausing
Signed-off-by: Andrew Thornton <[email protected]>
1 parent a73c034 commit 8866235

File tree

5 files changed

+95
-0
lines changed

5 files changed

+95
-0
lines changed

modules/queue/manager.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,12 @@ func (q *ManagedQueue) AddWorkers(number int, timeout time.Duration) context.Can
310310
return nil
311311
}
312312

313+
// Flushable returns true if the queue is flushable
314+
func (q *ManagedQueue) Flushable() bool {
315+
_, ok := q.Managed.(Flushable)
316+
return ok
317+
}
318+
313319
// Flush flushes the queue with a timeout
314320
func (q *ManagedQueue) Flush(timeout time.Duration) error {
315321
if flushable, ok := q.Managed.(Flushable); ok {
@@ -327,6 +333,34 @@ func (q *ManagedQueue) IsEmpty() bool {
327333
return true
328334
}
329335

336+
// Pausable returns whether the queue is Pausable
337+
func (q *ManagedQueue) Pausable() bool {
338+
_, ok := q.Managed.(Pausable)
339+
return ok
340+
}
341+
342+
// Pause pauses the queue
343+
func (q *ManagedQueue) Pause() {
344+
if pausable, ok := q.Managed.(Pausable); ok {
345+
pausable.Pause()
346+
}
347+
}
348+
349+
// IsPaused reveals if the queue is paused
350+
func (q *ManagedQueue) IsPaused() bool {
351+
if pausable, ok := q.Managed.(Pausable); ok {
352+
return pausable.IsPaused()
353+
}
354+
return false
355+
}
356+
357+
// Resume resumes the queue
358+
func (q *ManagedQueue) Resume() {
359+
if pausable, ok := q.Managed.(Pausable); ok {
360+
pausable.Resume()
361+
}
362+
}
363+
330364
// NumberOfWorkers returns the number of workers in the queue
331365
func (q *ManagedQueue) NumberOfWorkers() int {
332366
if pool, ok := q.Managed.(ManagedPool); ok {

options/locale/locale_en-US.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2540,6 +2540,12 @@ monitor.queue.pool.flush.title = Flush Queue
25402540
monitor.queue.pool.flush.desc = Flush will add a worker that will terminate once the queue is empty, or it times out.
25412541
monitor.queue.pool.flush.submit = Add Flush Worker
25422542
monitor.queue.pool.flush.added = Flush Worker added for %[1]s
2543+
monitor.queue.pool.pause.title = Pause Queue
2544+
monitor.queue.pool.pause.desc = Pausing a Queue will prevent it from processing data
2545+
monitor.queue.pool.pause.submit = Pause Queue
2546+
monitor.queue.pool.resume.title = Resume Queue
2547+
monitor.queue.pool.resume.desc = Set this queue to resume work
2548+
monitor.queue.pool.resume.submit = Resume Queue
25432549

25442550
monitor.queue.settings.title = Pool Settings
25452551
monitor.queue.settings.desc = Pools dynamically grow with a boost in response to their worker queue blocking. These changes will not affect current worker groups.

routers/admin/admin.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,30 @@ func Flush(ctx *context.Context) {
392392
ctx.Redirect(setting.AppSubURL + "/admin/monitor/queue/" + strconv.FormatInt(qid, 10))
393393
}
394394

395+
// Pause pauses a queue
396+
func Pause(ctx *context.Context) {
397+
qid := ctx.ParamsInt64("qid")
398+
mq := queue.GetManager().GetManagedQueue(qid)
399+
if mq == nil {
400+
ctx.Status(404)
401+
return
402+
}
403+
mq.Pause()
404+
ctx.Redirect(setting.AppSubURL + "/admin/monitor/queue/" + strconv.FormatInt(qid, 10))
405+
}
406+
407+
// Resume resumes a queue
408+
func Resume(ctx *context.Context) {
409+
qid := ctx.ParamsInt64("qid")
410+
mq := queue.GetManager().GetManagedQueue(qid)
411+
if mq == nil {
412+
ctx.Status(404)
413+
return
414+
}
415+
mq.Resume()
416+
ctx.Redirect(setting.AppSubURL + "/admin/monitor/queue/" + strconv.FormatInt(qid, 10))
417+
}
418+
395419
// AddWorkers adds workers to a worker group
396420
func AddWorkers(ctx *context.Context) {
397421
qid := ctx.ParamsInt64("qid")

routers/routes/web.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,8 @@ func RegisterRoutes(m *web.Route) {
452452
m.Post("/add", admin.AddWorkers)
453453
m.Post("/cancel/{pid}", admin.WorkerCancel)
454454
m.Post("/flush", admin.Flush)
455+
m.Post("/pause", admin.Pause)
456+
m.Post("/resume", admin.Resume)
455457
})
456458
})
457459

templates/admin/queue.tmpl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,35 @@
9292
</div>
9393
</form>
9494
</div>
95+
{{if .Queue.Pausable}}
96+
{{if .Queue.IsPaused}}
97+
<h4 class="ui top attached header">
98+
{{.i18n.Tr "admin.monitor.queue.pool.resume.title"}}
99+
</h4>
100+
<div class="ui attached segment">
101+
<p>{{.i18n.Tr "admin.monitor.queue.pool.resume.desc"}}</p>
102+
<form method="POST" action="{{.Link}}/resume">
103+
{{$.CsrfTokenHtml}}
104+
<div class="ui form">
105+
<button class="ui submit button">{{.i18n.Tr "admin.monitor.queue.pool.resume.submit"}}</button>
106+
</div>
107+
</form>
108+
</div>
109+
{{else}}
110+
<h4 class="ui top attached header">
111+
{{.i18n.Tr "admin.monitor.queue.pool.pause.title"}}
112+
</h4>
113+
<div class="ui attached segment">
114+
<p>{{.i18n.Tr "admin.monitor.queue.pool.pause.desc"}}</p>
115+
<form method="POST" action="{{.Link}}/pause">
116+
{{$.CsrfTokenHtml}}
117+
<div class="ui form">
118+
<button class="ui submit button">{{.i18n.Tr "admin.monitor.queue.pool.pause.submit"}}</button>
119+
</div>
120+
</form>
121+
</div>
122+
{{end}}
123+
{{end}}
95124
<h4 class="ui top attached header">
96125
{{.i18n.Tr "admin.monitor.queue.pool.flush.title"}}
97126
</h4>

0 commit comments

Comments
 (0)