0
0
mirror of https://github.com/thegeeklab/wp-s3-action.git synced 2024-11-10 04:40:38 +00:00

Move invalidate to the end for safety

This commit is contained in:
Eric Anderson 2016-03-14 17:12:37 -04:00
parent d3dfcec164
commit 811766f556

52
main.go
View File

@ -54,7 +54,7 @@ func main() {
os.Exit(1) os.Exit(1)
} }
a.createClient() a.createClient()
a.createSyncJobs() a.createSyncJobs()
a.createInvalidateJob() a.createInvalidateJob()
@ -74,7 +74,7 @@ func newApp() *app {
func (a *app) loadVargs() error { func (a *app) loadVargs() error {
plugin.Param("vargs", a.vargs) plugin.Param("vargs", a.vargs)
plugin.Param("workspace", a.workspace) plugin.Param("workspace", a.workspace)
err := plugin.Parse() err := plugin.Parse()
return err return err
@ -153,25 +153,25 @@ func (a *app) createSyncJobs() {
action: "redirect", action: "redirect",
}) })
} }
if (a.vargs.Delete) { if a.vargs.Delete {
for _, r := range remote { for _, r := range remote {
found := false found := false
for _, l := range local { for _, l := range local {
if l == r { if l == r {
found = true found = true
break break
} }
} }
if !found { if !found {
a.jobs = append(a.jobs, job{ a.jobs = append(a.jobs, job{
local: "", local: "",
remote: r, remote: r,
action: "delete", action: "delete",
}) })
} }
} }
} }
} }
func (a *app) createInvalidateJob() { func (a *app) createInvalidateJob() {
@ -189,6 +189,7 @@ func (a *app) runJobs() {
client := a.client client := a.client
jobChan := make(chan struct{}, maxConcurrent) jobChan := make(chan struct{}, maxConcurrent)
results := make(chan *result, len(a.jobs)) results := make(chan *result, len(a.jobs))
var invalidateJob *job
fmt.Printf("Synchronizing with bucket \"%s\"\n", vargs.Bucket) fmt.Printf("Synchronizing with bucket \"%s\"\n", vargs.Bucket)
for _, j := range a.jobs { for _, j := range a.jobs {
@ -202,7 +203,8 @@ func (a *app) runJobs() {
} else if j.action == "delete" { } else if j.action == "delete" {
err = client.Delete(j.remote) err = client.Delete(j.remote)
} else if j.action == "invalidateCloudFront" { } else if j.action == "invalidateCloudFront" {
client.Invalidate(j.remote) invalidateJob = &j
// err = client.Invalidate(j.remote)
} else { } else {
err = nil err = nil
} }
@ -218,6 +220,14 @@ func (a *app) runJobs() {
os.Exit(1) os.Exit(1)
} }
} }
if invalidateJob != nil {
err := client.Invalidate(invalidateJob.remote)
if err != nil {
fmt.Printf("ERROR: failed to %s %s to %s: %+v\n", invalidateJob.action, invalidateJob.local, invalidateJob.remote, err)
os.Exit(1)
}
}
} }
func debug(format string, args ...interface{}) { func debug(format string, args ...interface{}) {