(ctx context.Context, db *database.Client)
| 120 | } |
| 121 | |
| 122 | func (cli *cliPapi) sync(ctx context.Context, db *database.Client) error { |
| 123 | cfg := cli.cfg() |
| 124 | |
| 125 | apic, err := apiserver.NewAPIC(ctx, cfg.API.Server.OnlineClient, db, cfg.API.Server.ConsoleConfig, cfg.API.Server.CapiWhitelists) |
| 126 | if err != nil { |
| 127 | return fmt.Errorf("unable to initialize API client: %w", err) |
| 128 | } |
| 129 | |
| 130 | g, ctx := errgroup.WithContext(ctx) |
| 131 | g.Go(func() error { return apic.Push(ctx) }) |
| 132 | |
| 133 | papiLogger := cfg.API.Server.NewPAPILogger() |
| 134 | papi, err := apiserver.NewPAPI(apic, db, cfg.API.Server.ConsoleConfig, papiLogger) |
| 135 | if err != nil { |
| 136 | return fmt.Errorf("unable to initialize PAPI client: %w", err) |
| 137 | } |
| 138 | |
| 139 | g.Go(func() error { return papi.SyncDecisions(ctx) }) |
| 140 | |
| 141 | err = papi.PullOnce(ctx, time.Time{}, true) |
| 142 | if err != nil { |
| 143 | return fmt.Errorf("unable to sync decisions: %w", err) |
| 144 | } |
| 145 | |
| 146 | log.Infof("Sending acknowledgements to CAPI") |
| 147 | |
| 148 | apic.Shutdown() |
| 149 | papi.Shutdown() |
| 150 | _ = g.Wait() |
| 151 | time.Sleep(5 * time.Second) // FIXME: the push done by apic.Push is run inside a sub goroutine, sleep to make sure it's done |
| 152 | |
| 153 | return nil |
| 154 | } |
| 155 | |
| 156 | func (cli *cliPapi) newSyncCmd() *cobra.Command { |
| 157 | cmd := &cobra.Command{ |
no test coverage detected