Skip to content

Commit

Permalink
fix(server): use a new db worker for hot updates (#2581)
Browse files Browse the repository at this point in the history
Co-authored-by: knqyf263 <knqyf263@gmail.com>
  • Loading branch information
afdesk and knqyf263 committed Jul 25, 2022
1 parent 769ed55 commit fa8a8ba
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions pkg/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,16 @@ func (c *Client) Download(ctx context.Context, dst string) error {
log.Logger.Debug("no metadata file")
}

if err := c.populateOCIArtifact(); err != nil {
art, err := c.initOCIArtifact()
if err != nil {
return xerrors.Errorf("OCI artifact error: %w", err)
}

if err := c.artifact.Download(ctx, db.Dir(dst)); err != nil {
if err = art.Download(ctx, db.Dir(dst)); err != nil {
return xerrors.Errorf("database download error: %w", err)
}

if err := c.updateDownloadedAt(dst); err != nil {
if err = c.updateDownloadedAt(dst); err != nil {
return xerrors.Errorf("failed to update downloaded_at: %w", err)
}
return nil
Expand All @@ -182,14 +183,15 @@ func (c *Client) updateDownloadedAt(dst string) error {
return nil
}

func (c *Client) populateOCIArtifact() error {
if c.artifact == nil {
repo := fmt.Sprintf("%s:%d", c.dbRepository, db.SchemaVersion)
art, err := oci.NewArtifact(repo, dbMediaType, c.quiet, c.insecureSkipTLSVerify)
if err != nil {
return xerrors.Errorf("OCI artifact error: %w", err)
}
c.artifact = art
func (c *Client) initOCIArtifact() (*oci.Artifact, error) {
if c.artifact != nil {
return c.artifact, nil
}
return nil

repo := fmt.Sprintf("%s:%d", c.dbRepository, db.SchemaVersion)
art, err := oci.NewArtifact(repo, dbMediaType, c.quiet, c.insecureSkipTLSVerify)
if err != nil {
return nil, xerrors.Errorf("OCI artifact error: %w", err)
}
return art, nil
}

0 comments on commit fa8a8ba

Please sign in to comment.