From ff8f013b567da74ab04b329684d6e7fc52e3e212 Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Mon, 27 Mar 2023 11:11:28 +0200 Subject: [PATCH] Make archive migration threaded --- tools/archive-migration/main.go | 69 +++++++++++++++++---------------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/tools/archive-migration/main.go b/tools/archive-migration/main.go index 4bcb8a1..70e4df2 100644 --- a/tools/archive-migration/main.go +++ b/tools/archive-migration/main.go @@ -207,42 +207,45 @@ func main() { } for job := range ar.Iter() { - fmt.Printf("Job %d\n", job.JobID) + // fmt.Printf("Job %d\n", job.JobID) + job := job - path := getPath(job, dstPath, "meta.json") - err = os.MkdirAll(filepath.Dir(path), 0750) - if err != nil { - log.Fatal(err) - } - f, err := os.Create(path) - if err != nil { - log.Fatal(err) - } + go func() { + path := getPath(job, dstPath, "meta.json") + err = os.MkdirAll(filepath.Dir(path), 0750) + if err != nil { + log.Fatal(err) + } + f, err := os.Create(path) + if err != nil { + log.Fatal(err) + } - jmn := deepCopyJobMeta(job) - if err = EncodeJobMeta(f, &jmn); err != nil { - log.Fatal(err) - } - if err = f.Close(); err != nil { - log.Fatal(err) - } + jmn := deepCopyJobMeta(job) + if err = EncodeJobMeta(f, &jmn); err != nil { + log.Fatal(err) + } + if err = f.Close(); err != nil { + log.Fatal(err) + } - f, err = os.Create(getPath(job, dstPath, "data.json")) - if err != nil { - log.Fatal(err) - } + f, err = os.Create(getPath(job, dstPath, "data.json")) + if err != nil { + log.Fatal(err) + } - var jd *JobData - jd, err = loadJobData(getPath(job, srcPath, "data.json")) - if err != nil { - log.Fatal(err) - } - jdn := deepCopyJobData(jd) - if err := EncodeJobData(f, &jdn); err != nil { - log.Fatal(err) - } - if err := f.Close(); err != nil { - log.Fatal(err) - } + var jd *JobData + jd, err = loadJobData(getPath(job, srcPath, "data.json")) + if err != nil { + log.Fatal(err) + } + jdn := deepCopyJobData(jd) + if err := EncodeJobData(f, &jdn); err != nil { + log.Fatal(err) + } + if err := f.Close(); err != nil { + log.Fatal(err) + } + }() } }