From a7126cac639cdcf2208fa6c42566a9416ca40ef2 Mon Sep 17 00:00:00 2001 From: link Date: Fri, 17 Feb 2023 18:40:19 +0800 Subject: [PATCH] Rotational training registration to message-bus (#903) --- .../usr/lib/systemd/system/rclone.service | 2 +- main.go | 20 +++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/build/sysroot/usr/lib/systemd/system/rclone.service b/build/sysroot/usr/lib/systemd/system/rclone.service index caa6bf403..621e87e64 100644 --- a/build/sysroot/usr/lib/systemd/system/rclone.service +++ b/build/sysroot/usr/lib/systemd/system/rclone.service @@ -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 diff --git a/main.go b/main.go index 8e961720a..c169f5107 100644 --- a/main.go +++ b/main.go @@ -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() {