From 60af66d9ba77a61e61ef71d02c8e30198c433c87 Mon Sep 17 00:00:00 2001 From: Nick White Date: Tue, 19 May 2020 15:23:55 +0100 Subject: Add getandpurgequeue debugging tool --- cmd/getandpurgequeue/main.go | 85 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 cmd/getandpurgequeue/main.go (limited to 'cmd') diff --git a/cmd/getandpurgequeue/main.go b/cmd/getandpurgequeue/main.go new file mode 100644 index 0000000..33aef60 --- /dev/null +++ b/cmd/getandpurgequeue/main.go @@ -0,0 +1,85 @@ +// Copyright 2019 Nick White. +// Use of this source code is governed by the GPLv3 +// license that can be found in the LICENSE file. + +// getandpurgequeue gets and deletes all messages from a queue. This can +// be useful for debugging queue issues. +package main + +import ( + "flag" + "fmt" + "log" + + "rescribe.xyz/bookpipeline" +) + +const usage = `Usage: getandpurgequeue qname + +getandpurgequeue gets and deletes all messages from a queue. + +This can be useful for debugging queue issues. + +Valid queue names: +- preprocess +- wipeonly +- ocrpage +- analyse +` + +type QueuePipeliner interface { + Init() error + LogAndPurgeQueue(url string) error + PreQueueId() string + WipeQueueId() string + OCRPageQueueId() string + AnalyseQueueId() string +} + +func main() { + flag.Usage = func() { + fmt.Fprintf(flag.CommandLine.Output(), usage) + flag.PrintDefaults() + } + flag.Parse() + + if flag.NArg() != 1 { + flag.Usage() + return + } + + var conn QueuePipeliner + conn = &bookpipeline.AwsConn{Region: "eu-west-2"} + + err := conn.Init() + if err != nil { + log.Fatalln("Error setting up cloud connection:", err) + } + + qdetails := []struct { + id, name string + }{ + {conn.PreQueueId(), "preprocess"}, + {conn.WipeQueueId(), "wipeonly"}, + {conn.OCRPageQueueId(), "ocrpage"}, + {conn.AnalyseQueueId(), "analyse"}, + } + + qname := flag.Arg(0) + + var qid string + for i, n := range qdetails { + if n.name == qname { + qid = qdetails[i].id + break + } + } + if qid == "" { + log.Fatalln("Error, no queue named", qname) + } + + err = conn.LogAndPurgeQueue(qid) + if err != nil { + log.Fatalln("Error getting and purging queue", qname, ":", err) + } +} -- cgit v1.2.1-24-ge1ad