-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Network switch mangos to nats #306
base: main
Are you sure you want to change the base?
Changes from 4 commits
df0d89f
d1cbca6
59ea89a
9cd6bf6
ea9f9c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
FROM golang:1.23.3-alpine3.20 as builder | ||
ARG APP=/app | ||
WORKDIR ${APP} | ||
|
||
RUN apk add --no-cache make | ||
# disable cgo for go build | ||
ENV CGO_ENABLED=0 | ||
|
||
COPY go.mod . | ||
COPY go.sum . | ||
|
||
RUN go mod download | ||
|
||
COPY Makefile . | ||
COPY cmd cmd | ||
COPY pkg pkg | ||
COPY internal internal | ||
|
||
RUN make build-messaging-server-linux-amd64 | ||
|
||
FROM alpine:3.20 | ||
ARG APP=/app | ||
ENV TZ=Etc/UTC \ | ||
APP_USER=appuser | ||
|
||
STOPSIGNAL SIGINT | ||
|
||
RUN addgroup -S $APP_USER \ | ||
&& adduser -S $APP_USER -G $APP_USER | ||
|
||
RUN apk add --no-cache bind-tools | ||
|
||
USER $APP_USER | ||
WORKDIR ${APP} | ||
# Considered as a default HTTP API Port | ||
EXPOSE 8080 | ||
|
||
COPY --from=builder ${APP}/build/linux-amd64/messaging-server ${APP}/messaging-server | ||
|
||
ENTRYPOINT ["./messaging-server"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,8 +22,6 @@ import ( | |
"github.com/bwmarrin/discordgo" | ||
"github.com/pkg/errors" | ||
"github.com/wavesplatform/gowaves/pkg/crypto" | ||
"go.nanomsg.org/mangos/v3" | ||
"go.nanomsg.org/mangos/v3/protocol" | ||
"go.uber.org/zap" | ||
"gopkg.in/telebot.v3" | ||
) | ||
|
@@ -80,12 +78,12 @@ func (s *subscriptions) MapR(f func()) { | |
type DiscordBotEnvironment struct { | ||
ChatID string | ||
Bot *discordgo.Session | ||
subSocket protocol.Socket | ||
Subscriptions subscriptions | ||
zap *zap.Logger | ||
requestType chan<- pair.Request | ||
responsePairType <-chan pair.Response | ||
unhandledAlertMessages unhandledAlertMessages | ||
scheme string | ||
} | ||
|
||
func NewDiscordBotEnvironment( | ||
|
@@ -94,6 +92,7 @@ func NewDiscordBotEnvironment( | |
zap *zap.Logger, | ||
requestType chan<- pair.Request, | ||
responsePairType <-chan pair.Response, | ||
scheme string, | ||
) *DiscordBotEnvironment { | ||
return &DiscordBotEnvironment{ | ||
Bot: bot, | ||
|
@@ -106,6 +105,7 @@ func NewDiscordBotEnvironment( | |
requestType: requestType, | ||
responsePairType: responsePairType, | ||
unhandledAlertMessages: newUnhandledAlertMessages(), | ||
scheme: scheme, | ||
} | ||
} | ||
|
||
|
@@ -121,10 +121,6 @@ func (dscBot *DiscordBotEnvironment) Start() error { | |
return nil | ||
} | ||
|
||
func (dscBot *DiscordBotEnvironment) SetSubSocket(subSocket protocol.Socket) { | ||
dscBot.subSocket = subSocket | ||
} | ||
|
||
func (dscBot *DiscordBotEnvironment) SendMessage(msg string) { | ||
_, err := dscBot.Bot.ChannelMessageSend(dscBot.ChatID, msg) | ||
if err != nil { | ||
|
@@ -194,10 +190,10 @@ func (dscBot *DiscordBotEnvironment) SubscribeToAllAlerts() error { | |
if dscBot.IsAlreadySubscribed(alertType) { | ||
return errors.Errorf("failed to subscribe to %s, already subscribed to it", alertName) | ||
} | ||
err := dscBot.subSocket.SetOption(mangos.OptionSubscribe, []byte{byte(alertType)}) | ||
if err != nil { | ||
return err | ||
} | ||
// err := dscBot.subSocket.SetOption(mangos.OptionSubscribe, []byte{byte(alertType)}). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comments? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The file you viewed is outdated |
||
// if err != nil { | ||
// return err | ||
// } | ||
dscBot.Subscriptions.Add(alertType, alertName) | ||
dscBot.zap.Sugar().Infof("subscribed to %s", alertName) | ||
} | ||
|
@@ -244,13 +240,13 @@ func (m unhandledAlertMessages) Delete(alertID crypto.Digest) { | |
type TelegramBotEnvironment struct { | ||
ChatID int64 | ||
Bot *telebot.Bot | ||
Mute bool // If it used elsewhere, should be protected by mutex | ||
subSocket protocol.Socket | ||
Mute bool // If it used elsewhere, should be protected by mutex. | ||
subscriptions subscriptions | ||
zap *zap.Logger | ||
requestType chan<- pair.Request | ||
responsePairType <-chan pair.Response | ||
unhandledAlertMessages unhandledAlertMessages | ||
scheme string | ||
} | ||
|
||
func NewTelegramBotEnvironment( | ||
|
@@ -260,6 +256,7 @@ func NewTelegramBotEnvironment( | |
zap *zap.Logger, | ||
requestType chan<- pair.Request, | ||
responsePairType <-chan pair.Response, | ||
scheme string, | ||
) *TelegramBotEnvironment { | ||
return &TelegramBotEnvironment{ | ||
Bot: bot, | ||
|
@@ -273,6 +270,7 @@ func NewTelegramBotEnvironment( | |
requestType: requestType, | ||
responsePairType: responsePairType, | ||
unhandledAlertMessages: newUnhandledAlertMessages(), | ||
scheme: scheme, | ||
} | ||
} | ||
|
||
|
@@ -289,10 +287,6 @@ func (tgEnv *TelegramBotEnvironment) Start(ctx context.Context) error { | |
return nil | ||
} | ||
|
||
func (tgEnv *TelegramBotEnvironment) SetSubSocket(subSocket protocol.Socket) { | ||
tgEnv.subSocket = subSocket | ||
} | ||
|
||
func (tgEnv *TelegramBotEnvironment) SendAlertMessage(msg generalMessaging.AlertMessage) { | ||
if tgEnv.Mute { | ||
tgEnv.zap.Info("received an alert, but asleep now") | ||
|
@@ -425,10 +419,11 @@ func (tgEnv *TelegramBotEnvironment) SubscribeToAllAlerts() error { | |
if tgEnv.IsAlreadySubscribed(alertType) { | ||
return errors.Errorf("failed to subscribe to %s, already subscribed to it", alertName) | ||
} | ||
err := tgEnv.subSocket.SetOption(mangos.OptionSubscribe, []byte{byte(alertType)}) | ||
if err != nil { | ||
return err | ||
} | ||
// todo fix this. send (topic, handlerFunc) into this function | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO |
||
// err := tgEnv.subSocket.SetOption(mangos.OptionSubscribe, []byte{byte(alertType)}). | ||
// if err != nil {. | ||
// return err. | ||
// }. | ||
tgEnv.subscriptions.Add(alertType, alertName) | ||
tgEnv.zap.Sugar().Infof("Telegram bot subscribed to %s", alertName) | ||
} | ||
|
@@ -446,10 +441,11 @@ func (tgEnv *TelegramBotEnvironment) SubscribeToAlert(alertType entities.AlertTy | |
return errors.Errorf("failed to subscribe to %s, already subscribed to it", alertName) | ||
} | ||
|
||
err := tgEnv.subSocket.SetOption(mangos.OptionSubscribe, []byte{byte(alertType)}) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to subscribe to alert") | ||
} | ||
// todo fix this. send (topic, handlerFunc) into this function | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO |
||
// err := tgEnv.subSocket.SetOption(mangos.OptionSubscribe, []byte{byte(alertType)}). | ||
// if err != nil {. | ||
// return errors.Wrap(err, "failed to subscribe to alert"). | ||
// }. | ||
tgEnv.subscriptions.Add(alertType, alertName) | ||
tgEnv.zap.Sugar().Infof("Telegram bot subscribed to %s", alertName) | ||
return nil | ||
|
@@ -464,11 +460,11 @@ func (tgEnv *TelegramBotEnvironment) UnsubscribeFromAlert(alertType entities.Ale | |
if !tgEnv.IsAlreadySubscribed(alertType) { | ||
return errors.Errorf("failed to unsubscribe from %s, was not subscribed to it", alertName) | ||
} | ||
|
||
err := tgEnv.subSocket.SetOption(mangos.OptionUnsubscribe, []byte{byte(alertType)}) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to unsubscribe from alert") | ||
} | ||
// TODO fix this | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What exactly should be fixed? |
||
// err := tgEnv.subSocket.SetOption(mangos.OptionUnsubscribe, []byte{byte(alertType)}) | ||
// if err != nil { | ||
// return errors.Wrap(err, "failed to unsubscribe from alert") | ||
// } | ||
ok = tgEnv.IsAlreadySubscribed(alertType) | ||
if !ok { | ||
return errors.New("failed to unsubscribe from alert: was not subscribed to it") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it still necessary for discord?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can still type some commands as far as I remember