Skip to content
This repository has been archived by the owner on Nov 9, 2024. It is now read-only.

Commit

Permalink
Merge 95dc207 into 577de21
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ authored Nov 17, 2019
2 parents 577de21 + 95dc207 commit 6360ecd
Show file tree
Hide file tree
Showing 10 changed files with 306 additions and 45 deletions.
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM golang as builder

RUN apt-get update && apt-get install -y bash curl git go-dep libmagickwand-6.q16-dev
WORKDIR /go/src/github.com/analogj/lodestone-processor/
COPY . /go/src/github.com/analogj/lodestone-processor/
COPY 152-2009-R0911_A1.pdf /tmp/152-2009-R0911_A1.pdf
RUN dep ensure && \
go build -o processor ./cmd/main.go && \
./processor

#GOOS=linux GARCH=amd64 CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags "-X main.goos=linux -X main.goarch=amd64 -extldflags \"-static\"" -o lodestone-document-processor-linux-amd64 ./cmd/document-processor/document-processor.go && \
#GOOS=linux GARCH=amd64 CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags "-X main.goos=linux -X main.goarch=amd64 -extldflags \"-static\"" -o lodestone-thumbnail-processor-linux-amd64 ./cmd/thumbnail-processor/thumbnail-processor.go
#
#
#FROM debian:buster-slim as runtime
#
#RUN apt-get update && apt-get install -y bash curl git go-dep libmagickwand-6.q16-dev libreoffice-common
#COPY --from=builder /go/src/github.com/analogj/lodestone-processor/lodestone-document-processor-linux-amd64 /usr/bin/lodestone-document-processor
#COPY --from=builder /go/src/github.com/analogj/lodestone-processor/lodestone-thumbnail-processor-linux-amd64 /usr/bin/lodestone-thumbnail-processor
#
#RUN chmod +x /usr/bin/lodestone-document-processor /usr/bin/lodestone-thumbnail-processor
38 changes: 11 additions & 27 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@
name = "github.com/analogj/go-util"

[[constraint]]
version = "=v6.15.5"
name = "github.com/go-redis/redis"
name = "gopkg.in/gographics/imagick.v2"
version = "2.5.0"
5 changes: 3 additions & 2 deletions capsule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
engine_enable_code_mutation: true

engine_cmd_compile:
- 'GOOS=linux GARCH=amd64 CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags "-X main.goos=linux -X main.goarch=amd64 -extldflags \"-static\"" -o lodestone-document-processor-linux-amd64 ./cmd/document-processor/document-processor.go'
- 'GOOS=linux GARCH=amd64 CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags "-X main.goos=linux -X main.goarch=amd64 -extldflags \"-static\"" -o lodestone-thumbnail-processor-linux-amd64 ./cmd/thumbnail-processor/thumbnail-processor.go'
- 'apt-get update && apt-get install -y bash curl git go-dep libmagickwand-6.q16-dev libreoffice-common'
- 'go build -o lodestone-document-processor-linux-amd64 ./cmd/document-processor/document-processor.go'
- 'go build -o lodestone-thumbnail-processor-linux-amd64 ./cmd/thumbnail-processor/thumbnail-processor.go'
engine_cmd_test: 'go test -v ./...'
engine_disable_lint: true

Expand Down
15 changes: 11 additions & 4 deletions cmd/document-processor/document-processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/analogj/go-util/utils"
"github.com/analogj/lodestone-processor/pkg/listen"
"github.com/analogj/lodestone-processor/pkg/processor"
"github.com/analogj/lodestone-processor/pkg/version"
"github.com/fatih/color"
"github.com/urfave/cli"
Expand Down Expand Up @@ -56,19 +57,25 @@ func main() {

listenClient = new(listen.AmqpListen)
err := listenClient.Init(map[string]string{
"amqp-url": c.String("amqp-url"),
"exchange": c.String("amqp-exchange"),
"queue": c.String("amqp-queue"),
"amqp-url": c.String("amqp-url"),
"exchange": c.String("amqp-exchange"),
"queue": c.String("amqp-queue"),
"storage-url": c.String("storage-url"),
})
if err != nil {
return err
}
defer listenClient.Close()

return listenClient.Subscribe()
return listenClient.Subscribe(processor.DocumentProcessor)
},

Flags: []cli.Flag{
&cli.StringFlag{
Name: "storage-url",
Usage: "The storage server url",
Value: "http://storage:9000",
},

&cli.StringFlag{
Name: "amqp-url",
Expand Down
16 changes: 12 additions & 4 deletions cmd/thumbnail-processor/thumbnail-processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/analogj/go-util/utils"
"github.com/analogj/lodestone-processor/pkg/listen"
"github.com/analogj/lodestone-processor/pkg/processor"
"github.com/analogj/lodestone-processor/pkg/version"
"github.com/fatih/color"
"github.com/urfave/cli"
Expand Down Expand Up @@ -56,20 +57,27 @@ func main() {

listenClient = new(listen.AmqpListen)
err := listenClient.Init(map[string]string{
"amqp-url": c.String("amqp-url"),
"exchange": c.String("amqp-exchange"),
"queue": c.String("amqp-queue"),
"amqp-url": c.String("amqp-url"),
"exchange": c.String("amqp-exchange"),
"queue": c.String("amqp-queue"),
"storage-url": c.String("storage-url"),
})
if err != nil {
return err
}
defer listenClient.Close()

return listenClient.Subscribe()
return listenClient.Subscribe(processor.ThumbnailProcessor)
},

Flags: []cli.Flag{

&cli.StringFlag{
Name: "storage-url",
Usage: "The storage server url",
Value: "http://storage:9000",
},

&cli.StringFlag{
Name: "amqp-url",
Usage: "The amqp connection string",
Expand Down
16 changes: 11 additions & 5 deletions pkg/listen/amqp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ import (
)

type AmqpListen struct {
client *amqp.Connection
channel *amqp.Channel
exchange string
queue string
client *amqp.Connection
channel *amqp.Channel
exchange string
queue string
storageUrl string
}

func (n *AmqpListen) Init(config map[string]string) error {
n.exchange = config["exchange"]
n.queue = config["queue"]
n.storageUrl = config["storage-url"]

client, err := amqp.Dial(config["amqp-url"])
if err != nil {
Expand Down Expand Up @@ -58,7 +60,7 @@ func (n *AmqpListen) Init(config map[string]string) error {
return err
}

func (n *AmqpListen) Subscribe() error {
func (n *AmqpListen) Subscribe(processor func(body []byte, storageUrl string) error) error {
fmt.Println("Subscribe to events..")

err := n.channel.QueueBind(
Expand Down Expand Up @@ -89,6 +91,10 @@ func (n *AmqpListen) Subscribe() error {
go func() {
for d := range msgs {
log.Printf(" [x] %s", d.Body)
if err := processor(d.Body, n.storageUrl); err != nil {
log.Printf("Error when processing document %s", err)
//TODO: add to the dead letter queue (for further processing later)
}
}
}()

Expand Down
2 changes: 1 addition & 1 deletion pkg/listen/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package listen

type Interface interface {
Init(config map[string]string) error
Subscribe() error
Subscribe(processor func(body []byte, storageUrl string) error) error
Close() error
}
8 changes: 8 additions & 0 deletions pkg/processor/document.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package processor

func DocumentProcessor(body []byte, storageUrl string) error {

//TODO pass document to TIKA

return nil
}
Loading

0 comments on commit 6360ecd

Please sign in to comment.