summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorNick White <git@njw.name>2019-12-16 16:05:47 +0000
committerNick White <git@njw.name>2019-12-16 16:05:47 +0000
commitd4c42f851cb2254a27940721de3e3ef2d73f2910 (patch)
treeb886e8eed89a769a276cd0124103e97ff422f7f4 /cmd
parent70eecf79704452d600f3edca9dec2e9726dcfe6d (diff)
Add a new tool, addtoqueue, which can be used to generically add any message to any queue
Diffstat (limited to 'cmd')
-rw-r--r--cmd/addtoanalysequeue/main.go72
-rw-r--r--cmd/addtoqueue/main.go93
2 files changed, 93 insertions, 72 deletions
diff --git a/cmd/addtoanalysequeue/main.go b/cmd/addtoanalysequeue/main.go
deleted file mode 100644
index c9a34c7..0000000
--- a/cmd/addtoanalysequeue/main.go
+++ /dev/null
@@ -1,72 +0,0 @@
-package main
-
-import (
- "flag"
- "fmt"
- "log"
- "os"
-
- "rescribe.xyz/bookpipeline"
-)
-
-const usage = `Usage: addtoanalysequeue [-v] bookname
-
-addtoanalysequeue adds a book it to the Analyse queue.
-
-This should be done automatically by the bookpipeline tool once
-the OCR job has completed, but sometimes it isn't, because of a
-bug where if a file that is named like a preprocessed image
-doesn't have a hOCR component. Once that bug is squashed, this
-tool can be deleted.
-`
-
-// null writer to enable non-verbose logging to be discarded
-type NullWriter bool
-
-func (w NullWriter) Write(p []byte) (n int, err error) {
- return len(p), nil
-}
-
-type UnstickPipeliner interface {
- Init() error
- AddToQueue(url string, msg string) error
- AnalyseQueueId() string
-}
-
-func main() {
- verbose := flag.Bool("v", false, "verbose")
- flag.Usage = func() {
- fmt.Fprintf(flag.CommandLine.Output(), usage)
- flag.PrintDefaults()
- }
- flag.Parse()
-
- if flag.NArg() != 1 {
- flag.Usage()
- return
- }
-
- var verboselog *log.Logger
- if *verbose {
- verboselog = log.New(os.Stdout, "", 0)
- } else {
- var n NullWriter
- verboselog = log.New(n, "", 0)
- }
-
- var conn UnstickPipeliner
- conn = &bookpipeline.AwsConn{Region: "eu-west-2", Logger: verboselog}
-
- err := conn.Init()
- if err != nil {
- log.Fatalln("Error setting up cloud connection:", err)
- }
-
- book := flag.Arg(0)
-
- err = conn.AddToQueue(conn.AnalyseQueueId(), book)
- if err != nil {
- log.Fatalln("Error adding message to Analyse queue:", err)
- }
- fmt.Println("Added message from to the Analyse queue.")
-}
diff --git a/cmd/addtoqueue/main.go b/cmd/addtoqueue/main.go
new file mode 100644
index 0000000..3549180
--- /dev/null
+++ b/cmd/addtoqueue/main.go
@@ -0,0 +1,93 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "log"
+
+ "rescribe.xyz/bookpipeline"
+)
+
+const usage = `Usage: addtoqueue qname msg
+
+addtoqueue adds a message to a queue.
+
+This is handy to work around bugs when things are misbehaving.
+
+Valid queue names:
+- preprocess
+- wipeonly
+- ocr
+- ocrpage
+- analyse
+`
+
+// null writer to enable non-verbose logging to be discarded
+type NullWriter bool
+
+func (w NullWriter) Write(p []byte) (n int, err error) {
+ return len(p), nil
+}
+
+type QueuePipeliner interface {
+ Init() error
+ AddToQueue(url string, msg string) error
+ PreQueueId() string
+ WipeQueueId() string
+ OCRQueueId() string
+ OCRPageQueueId() string
+ AnalyseQueueId() string
+}
+
+func main() {
+ flag.Usage = func() {
+ fmt.Fprintf(flag.CommandLine.Output(), usage)
+ flag.PrintDefaults()
+ }
+ flag.Parse()
+
+ if flag.NArg() != 2 {
+ flag.Usage()
+ return
+ }
+
+ var n NullWriter
+ quietlog := log.New(n, "", 0)
+ var conn QueuePipeliner
+ conn = &bookpipeline.AwsConn{Region: "eu-west-2", Logger: quietlog}
+
+ 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.OCRQueueId(), "ocr"},
+ {conn.OCRPageQueueId(), "ocrpage"},
+ {conn.AnalyseQueueId(), "analyse"},
+ }
+
+ qname := flag.Arg(0)
+ msg := flag.Arg(1)
+
+ 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.AddToQueue(qid, msg)
+ if err != nil {
+ log.Fatalln("Error adding message to", qname, "queue:", err)
+ }
+ fmt.Println("Added message to the queue.")
+}