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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
// Copyright 2019 Nick White.
// Use of this source code is governed by the GPLv3
// license that can be found in the LICENSE file.
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
- 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
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.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.")
}
|