From 16cf73911b262d189cec112ed0ba859bd9c4082f Mon Sep 17 00:00:00 2001 From: Sandip Agarwal Date: Fri, 1 Feb 2019 11:46:13 +0530 Subject: [PATCH 1/2] Post Update Callback provision --- s3update.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/s3update.go b/s3update.go index fa71b3c..6beeb6a 100644 --- a/s3update.go +++ b/s3update.go @@ -31,6 +31,8 @@ type Updater struct { S3ReleaseKey string // S3VersionKey represents the key on S3 to download the current version S3VersionKey string + // PostUpdateHandler represents the function to be passed that is to be run after pulling the app + PostUpdateHandler func(dest string) } // validate ensures every required fields is correctly set. Otherwise and error is returned. @@ -150,6 +152,11 @@ func runAutoUpdate(u Updater) error { // Removing backup os.Remove(destBackup) + // Run the PostUpdateHandler handler + if u.PostUpdateHandler != nil { + u.PostUpdateHandler(dest) + } + fmt.Printf("s3update: updated with success to version %d\nRestarting application\n", remoteVersion) // The update completed, we can now restart the application without requiring any user action. From 30deb5367040352de57dd2946c200440435bef29 Mon Sep 17 00:00:00 2001 From: Sandip Agarwal Date: Thu, 7 Feb 2019 19:07:13 +0530 Subject: [PATCH 2/2] Post Update Callback provision :: fail safe check --- s3update.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/s3update.go b/s3update.go index 6beeb6a..d6309e0 100644 --- a/s3update.go +++ b/s3update.go @@ -32,7 +32,7 @@ type Updater struct { // S3VersionKey represents the key on S3 to download the current version S3VersionKey string // PostUpdateHandler represents the function to be passed that is to be run after pulling the app - PostUpdateHandler func(dest string) + PostUpdateHandler func(dest string) error } // validate ensures every required fields is correctly set. Otherwise and error is returned. @@ -149,14 +149,19 @@ func runAutoUpdate(u Updater) error { return err } - // Removing backup - os.Remove(destBackup) - // Run the PostUpdateHandler handler if u.PostUpdateHandler != nil { - u.PostUpdateHandler(dest) + fmt.Printf("s3update: updating using post handler\n") + if err := u.PostUpdateHandler(dest); err != nil { + fmt.Printf("s3update: error updating using post handler :: %s\n", err) + os.Rename(destBackup, dest) + return err + } } + // Removing backup + os.Remove(destBackup) + fmt.Printf("s3update: updated with success to version %d\nRestarting application\n", remoteVersion) // The update completed, we can now restart the application without requiring any user action.