Refactor. Consul TTl fix, gracefull shutdown
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
bf47c8645d
commit
32f148ea95
@ -10,10 +10,10 @@ ARG BIN_OUTPUT
|
||||
ARG SVC_NAME
|
||||
ARG SVC_VER
|
||||
|
||||
LABEL author="Piotr Biernat"
|
||||
LABEL vendor="egommerce"
|
||||
LABEL service=${SVC_NAME}
|
||||
LABEL version=${SVC_VER}
|
||||
LABEL dev.egommerce.image.author="Piotr Biernat"
|
||||
LABEL dev.egommerce.image.service="api-eventubus"
|
||||
LABEL dev.egommerce.image.service=${SVC_NAME}
|
||||
LABEL dev.egommerce.image.version=${SVC_VER}
|
||||
|
||||
WORKDIR /
|
||||
COPY --from=builder $BIN_OUTPUT /app
|
||||
|
@ -12,7 +12,7 @@ TARGET=${1:-latest}
|
||||
|
||||
export DOCKER_BUILDKIT=1
|
||||
|
||||
docker build -t "$BUILDER_IMAGE" -f Dockerfile.builder . >/dev/null 2>&1 && echo "Successfully tagged $BUILDER_IMAGE"
|
||||
docker build -t "$BUILDER_IMAGE" -f Dockerfile.builder . && echo "Successfully tagged $BUILDER_IMAGE"
|
||||
|
||||
echo "Building target $IMAGE_PREFIX images..."
|
||||
if [ $TARGET = "latest" ]
|
||||
|
@ -5,10 +5,12 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"git.pbiernat.dev/egommerce/catalog-service/internal/app/config"
|
||||
"git.pbiernat.dev/egommerce/catalog-service/internal/app/database"
|
||||
"git.pbiernat.dev/egommerce/catalog-service/internal/app/event"
|
||||
"git.pbiernat.dev/egommerce/catalog-service/internal/app/server"
|
||||
"git.pbiernat.dev/egommerce/go-api-pkg/fluentd"
|
||||
amqp "git.pbiernat.dev/egommerce/go-api-pkg/rabbitmq"
|
||||
@ -103,7 +105,7 @@ func main() {
|
||||
forever := make(chan struct{})
|
||||
go func() {
|
||||
sigint := make(chan os.Signal, 1)
|
||||
signal.Notify(sigint, os.Interrupt, os.Kill, syscall.SIGINT, syscall.SIGTERM)
|
||||
signal.Notify(sigint, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
|
||||
<-sigint
|
||||
|
||||
logger.Log("Worker %s stopped working...\n", c.GetAppFullName())
|
||||
@ -120,20 +122,17 @@ func main() {
|
||||
continue
|
||||
}
|
||||
|
||||
event := fmt.Sprintf("%s", msg["event"])
|
||||
eName := fmt.Sprintf("%s", msg["event"])
|
||||
data := (msg["data"]).(map[string]interface{})
|
||||
logger.Log("Message<%s>: %s\n", event, data)
|
||||
logger.Log("Message<%s>: %s\n", eName, data)
|
||||
|
||||
// switch true {
|
||||
// case strings.Contains(event, amqp.EVENT_PRODUCT_ADD):
|
||||
// // create new basket and add product to it
|
||||
// logger.Log("Event: %s", amqp.EVENT_PRODUCT_ADD)
|
||||
// case strings.Contains(event, amqp.EVENT_PRODUCT_REMOVE):
|
||||
// // remove product from basket
|
||||
// logger.Log("Event: %s", amqp.EVENT_PRODUCT_REMOVE)
|
||||
// }
|
||||
switch true {
|
||||
case strings.Contains(eName, event.EVENT_WAREHOUSE_STOCK_UPDATED): // todo: first create such service ;)
|
||||
// update product available qty
|
||||
logger.Log("Event: %s", event.EVENT_WAREHOUSE_STOCK_UPDATED)
|
||||
}
|
||||
|
||||
logger.Log("ACK: %s", event)
|
||||
logger.Log("ACK: %s", eName)
|
||||
d.Ack(false)
|
||||
}
|
||||
}()
|
||||
|
@ -3,7 +3,7 @@ module git.pbiernat.dev/egommerce/catalog-service
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
git.pbiernat.dev/egommerce/go-api-pkg v0.0.31
|
||||
git.pbiernat.dev/egommerce/go-api-pkg v0.0.101
|
||||
github.com/gofiber/fiber/v2 v2.40.1
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/jackc/pgx/v4 v4.17.2
|
||||
|
16
src/go.sum
16
src/go.sum
@ -1,9 +1,13 @@
|
||||
git.pbiernat.dev/egommerce/go-api-pkg v0.0.29 h1:EG6t3i0P8ENH3eRYPgjVE8UHpnif8UPYA/23e1Nm6n0=
|
||||
git.pbiernat.dev/egommerce/go-api-pkg v0.0.29/go.mod h1:nAwcw2MZtn/54YKq8VQK6RJAsiuoLUtPuazXg8JcqK8=
|
||||
git.pbiernat.dev/egommerce/go-api-pkg v0.0.30 h1:qRUGkv/TA7vO6FDnKKxZ6CfooQVfp3/PpL3vGf6lwYY=
|
||||
git.pbiernat.dev/egommerce/go-api-pkg v0.0.30/go.mod h1:nAwcw2MZtn/54YKq8VQK6RJAsiuoLUtPuazXg8JcqK8=
|
||||
git.pbiernat.dev/egommerce/go-api-pkg v0.0.31 h1:TZOdMTp++vws86ZlwtWKmpoik5YN6aOSWRpu9j0FykU=
|
||||
git.pbiernat.dev/egommerce/go-api-pkg v0.0.31/go.mod h1:nAwcw2MZtn/54YKq8VQK6RJAsiuoLUtPuazXg8JcqK8=
|
||||
git.pbiernat.dev/egommerce/go-api-pkg v0.0.32 h1:ArB/n30m927WMAM4u51guH+qR0Lu4NGyYnYdi7OhlzY=
|
||||
git.pbiernat.dev/egommerce/go-api-pkg v0.0.32/go.mod h1:nAwcw2MZtn/54YKq8VQK6RJAsiuoLUtPuazXg8JcqK8=
|
||||
git.pbiernat.dev/egommerce/go-api-pkg v0.0.33 h1:1tm+pvUeS6OZLvHmLM3BwFS0Ty/eA3jDRuB60OicosA=
|
||||
git.pbiernat.dev/egommerce/go-api-pkg v0.0.33/go.mod h1:nAwcw2MZtn/54YKq8VQK6RJAsiuoLUtPuazXg8JcqK8=
|
||||
git.pbiernat.dev/egommerce/go-api-pkg v0.0.34 h1:UO1x6O+cyU7yYYbDCDyhhAypuf4QGIXcmWcBEEjLuYM=
|
||||
git.pbiernat.dev/egommerce/go-api-pkg v0.0.34/go.mod h1:nAwcw2MZtn/54YKq8VQK6RJAsiuoLUtPuazXg8JcqK8=
|
||||
git.pbiernat.dev/egommerce/go-api-pkg v0.0.100 h1:jw4fiGbZTsfJXJpGV+HQiYeMGZ7DMRMoepjuIwY6FIU=
|
||||
git.pbiernat.dev/egommerce/go-api-pkg v0.0.100/go.mod h1:nAwcw2MZtn/54YKq8VQK6RJAsiuoLUtPuazXg8JcqK8=
|
||||
git.pbiernat.dev/egommerce/go-api-pkg v0.0.101 h1:NZCFAAlC94+LcN1gjrENnWUHvpWgaNksyB2N4Fiy8C4=
|
||||
git.pbiernat.dev/egommerce/go-api-pkg v0.0.101/go.mod h1:nAwcw2MZtn/54YKq8VQK6RJAsiuoLUtPuazXg8JcqK8=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
|
||||
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
|
||||
|
@ -1,5 +1,10 @@
|
||||
package event
|
||||
|
||||
const (
|
||||
EVENT_PRODUCT_ADDED_TO_BASKET = "event.ProductAddedToBasketEvent"
|
||||
EVENT_PRODUCT_REMOVED_FROM_BASKET = "event.ProductRemovedFromBasketEvent"
|
||||
)
|
||||
|
||||
type ProductAddedToBasketEvent struct {
|
||||
*Event
|
||||
ProductID string `json:"product_id"`
|
||||
|
11
src/internal/app/event/warehouse.go
Normal file
11
src/internal/app/event/warehouse.go
Normal file
@ -0,0 +1,11 @@
|
||||
package event
|
||||
|
||||
const (
|
||||
EVENT_WAREHOUSE_STOCK_UPDATED = "event.WarehouseStockUpdatedEvent"
|
||||
)
|
||||
|
||||
type WarehouseStockUpdatedEvent struct {
|
||||
*Event
|
||||
ProductID string `json:"product_id"`
|
||||
NewQty int `json:"new_qty"`
|
||||
}
|
@ -72,7 +72,7 @@ func (s *Server) Start() {
|
||||
func (s *Server) StartWithGracefulShutdown(forever chan struct{}) {
|
||||
go func() {
|
||||
sigint := make(chan os.Signal, 1)
|
||||
signal.Notify(sigint, os.Interrupt, os.Kill, syscall.SIGINT, syscall.SIGTERM)
|
||||
signal.Notify(sigint, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
|
||||
<-sigint
|
||||
|
||||
if err := s.gracefulShutdown(); err != nil {
|
||||
@ -96,7 +96,6 @@ func (s *Server) GetRequestID(c *fiber.Ctx) (string, error) {
|
||||
}
|
||||
|
||||
return hdr.RequestID, nil
|
||||
|
||||
}
|
||||
|
||||
func (s *Server) gracefulShutdown() error {
|
||||
|
Loading…
Reference in New Issue
Block a user