Rotational training registration to message-bus (#903)

This commit is contained in:
link 2023-02-17 18:40:19 +08:00 committed by GitHub
parent 151aa037bb
commit a7126cac63
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 9 deletions

View file

@ -2,7 +2,7 @@
Description=rclone
[Service]
ExecStartPre=/usr/bin/rm -f /var/run/rclone/rclone.sock
ExecStartPre=/usr/bin/mkdir -p /var/run/rclone && /usr/bin/rm -f /var/run/rclone/rclone.sock
ExecStart=/usr/bin/rclone rcd --rc-addr unix:///var/run/rclone/rclone.sock --rc-no-auth --rc-allow-origin "*"
Restart=always
RestartSec=10

20
main.go
View file

@ -165,14 +165,18 @@ func main() {
events = append(events, message_bus.EventType{Name: "casaos:file:recover", SourceID: common.SERVICENAME, PropertyTypeList: []message_bus.PropertyType{}})
events = append(events, message_bus.EventType{Name: "casaos:file:operate", SourceID: common.SERVICENAME, PropertyTypeList: []message_bus.PropertyType{}})
// register at message bus
response, err := service.MyService.MessageBus().RegisterEventTypesWithResponse(context.Background(), events)
if err != nil {
logger.Error("error when trying to register one or more event types - some event type will not be discoverable", zap.Error(err))
}
if response != nil && response.StatusCode() != http.StatusOK {
logger.Error("error when trying to register one or more event types - some event type will not be discoverable", zap.String("status", response.Status()), zap.String("body", string(response.Body)))
for i := 0; i < 10; i++ {
response, err := service.MyService.MessageBus().RegisterEventTypesWithResponse(context.Background(), events)
if err != nil {
logger.Error("error when trying to register one or more event types - some event type will not be discoverable", zap.Error(err))
}
if response != nil && response.StatusCode() != http.StatusOK {
logger.Error("error when trying to register one or more event types - some event type will not be discoverable", zap.String("status", response.Status()), zap.String("body", string(response.Body)))
}
if response.StatusCode() == http.StatusOK {
break
}
time.Sleep(time.Second)
}
go func() {