Skip to content

Instantly share code, notes, and snippets.

@bmizerany
Created June 24, 2021 18:14
Show Gist options
  • Save bmizerany/986721417fde89acc60d225359b7c428 to your computer and use it in GitHub Desktop.
Save bmizerany/986721417fde89acc60d225359b7c428 to your computer and use it in GitHub Desktop.
package resume_test
import (
"context"
"log"
)
func ExampleBackup() {
backup := func(ctx context.Context, object string) error {
job, err := resume.Call(ctx, "start", backupStart, object)
if err != nil {
return err
}
q := "SELECT * FROM " + object // TODO(bmizerany): safely build query using schema
batch, err := resume.Call(ctx, "query", backupQuery, job, q)
if err != nil {
return err
}
results, err := resume.Call(ctx, "wait", backupWait, batch)
if err != nil {
return err
}
g := resume.NewGroup("results", ctx)
for _, r := range results {
g.Go("process", backupResult, r.URL)
}
if err := g.Wait(); err != nil {
return err
}
sum, err := resume.Call(ctx, "finish", backupFinish)
if err != nil {
return err
}
}
// optional: Type / Sequence annotations
// s := resume.NewAnnotation(ctx)
// s.Handle(1, "backup", "createJob")
// s.Handle(1, "backup", "query")
// s.Handle(1, "backup", "wait")
// s.Handle(1, "backup", "results")
// s.Handle(10000, "backup", "results", "process")
log.Fatal(resume.Run(ctx, s))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment