Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(digitalocean): make task + sidecar startup concurrent #122

Merged
merged 4 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/provider/digitalocean/digitalocean_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ func NewDigitalOceanProvider(ctx context.Context, logger *zap.Logger, providerNa
sshFingerprint: sshFingerprint,
}

logger.Info("petri tag", zap.String("tag", digitalOceanProvider.petriTag))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably remove this or move to debug


_, err = digitalOceanProvider.createTag(ctx, digitalOceanProvider.petriTag)

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion core/provider/digitalocean/droplet.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func (p *Provider) CreateDroplet(ctx context.Context, definition provider.TaskDe
if !ok {
return nil, fmt.Errorf("could not cast provider specific config to DigitalOceanConfig")
}

req := &godo.DropletCreateRequest{
Name: fmt.Sprintf("%s-%s", p.petriTag, definition.Name),
Region: doConfig.Region,
Expand Down Expand Up @@ -85,6 +84,7 @@ func (p *Provider) CreateDroplet(ctx context.Context, definition provider.TaskDe
}

p.logger.Info("droplet is active", zap.Duration("after", time.Since(start)), zap.String("task", definition.Name))
droplet = d
return true, nil
})

Expand Down
58 changes: 37 additions & 21 deletions core/provider/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
"sync"
)

Expand All @@ -26,34 +27,49 @@ func CreateTask(ctx context.Context, logger *zap.Logger, provider Provider, defi

sidecarTasks := make([]*Task, 0)

for _, sidecar := range definition.Sidecars {
if len(sidecar.Sidecars) > 0 {
return nil, errors.New("sidecar cannot have sidecar")
}
var eg errgroup.Group

id, err := provider.CreateTask(ctx, task.logger, sidecar)
if err != nil {
return nil, err
}
for i := range definition.Sidecars {
sidecar := definition.Sidecars[i]
eg.Go(func() error {
if len(sidecar.Sidecars) > 0 {
return errors.New("sidecar cannot have sidecar")
}

id, err := provider.CreateTask(ctx, task.logger, sidecar)
if err != nil {
return err
}

sidecarTasks = append(sidecarTasks, &Task{
Provider: provider,
Definition: sidecar,
ID: id,
Sidecars: make([]*Task, 0),
logger: task.logger,
})

sidecarTasks = append(sidecarTasks, &Task{
Provider: provider,
Definition: sidecar,
ID: id,
Sidecars: make([]*Task, 0),
logger: task.logger,
return nil
})
}

task.Sidecars = sidecarTasks

id, err := provider.CreateTask(ctx, logger, definition)
if err != nil {

eg.Go(func() error {
id, err := provider.CreateTask(ctx, logger, definition)
if err != nil {
return err
}

task.ID = id

return nil
})

if err := eg.Wait(); err != nil {
return nil, err
}

task.ID = id


task.Sidecars = sidecarTasks
return task, nil
}

Expand Down
2 changes: 1 addition & 1 deletion cosmos/cosmosutil/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (w *InteractingWallet) getTxResponse(ctx context.Context, txHash string) (s

clientCtx := client.Context{Client: cc, TxConfig: w.chain.GetTxConfig(), InterfaceRegistry: w.chain.GetInterfaceRegistry()}

err = util.WaitForCondition(ctx, time.Second*60, time.Second*1, func() (bool, error) {
err = util.WaitForCondition(ctx, time.Second*60, time.Millisecond * 100, func() (bool, error) {
res, err := authtx.QueryTx(clientCtx, txHash)

if err != nil {
Expand Down
Loading