Skip to content

Commit

Permalink
Merge pull request #120 from skip-mev/nv/caching-droplet-ips
Browse files Browse the repository at this point in the history
feat: allow caching of static droplet ips
  • Loading branch information
Eric-Warehime authored Nov 5, 2024
2 parents b93f7f9 + 96a82ba commit 8dd3c81
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions core/provider/digitalocean/droplet.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (p *Provider) CreateDroplet(ctx context.Context, definition provider.TaskDe

start := time.Now()

err = util.WaitForCondition(ctx, time.Second*100, time.Millisecond*100, func() (bool, error) {
err = util.WaitForCondition(ctx, time.Second*300, time.Millisecond*300, func() (bool, error) {
d, _, err := p.doClient.Droplets.Get(ctx, droplet.ID)

if err != nil {
Expand Down Expand Up @@ -119,13 +119,16 @@ func (p *Provider) deleteDroplet(ctx context.Context, name string) error {
return nil
}

func (p *Provider) getDroplet(ctx context.Context, name string) (*godo.Droplet, error) {
func (p *Provider) getDroplet(ctx context.Context, name string, returnOnCacheHit bool) (*godo.Droplet, error) {
cachedDroplet, ok := p.droplets.Load(name)

if !ok {
return nil, fmt.Errorf("could not find droplet %s", name)
}

if ok && returnOnCacheHit {
return cachedDroplet, nil
}

droplet, res, err := p.doClient.Droplets.Get(ctx, cachedDroplet.ID)

if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions core/provider/digitalocean/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (p *Provider) DestroyTask(ctx context.Context, taskName string) error {
}

func (p *Provider) GetTaskStatus(ctx context.Context, taskName string) (provider.TaskStatus, error) {
droplet, err := p.getDroplet(ctx, taskName)
droplet, err := p.getDroplet(ctx, taskName, false)

if err != nil {
return provider.TASK_STATUS_UNDEFINED, err
Expand Down Expand Up @@ -296,7 +296,7 @@ func (p *Provider) DownloadDir(ctx context.Context, s string, s2 string, s3 stri
}

func (p *Provider) GetIP(ctx context.Context, taskName string) (string, error) {
droplet, err := p.getDroplet(ctx, taskName)
droplet, err := p.getDroplet(ctx, taskName, true)

if err != nil {
return "", err
Expand Down

0 comments on commit 8dd3c81

Please sign in to comment.