Skip to content

Commit

Permalink
fix: clean schedule file #patch
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwelbm committed May 23, 2024
1 parent 65444ca commit 99f8484
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
7 changes: 4 additions & 3 deletions pkg/cmd/delete/edge_storage/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ func (b *bucket) runE(cmd *cobra.Command, _ []string) error {
}
}
logger.FInfo(b.factory.IOStreams.Out, "Delete all objects from bucket\n")
if err := deleteAllObjects(client, ctx, b.name, ""); err != nil {
logger.FInfo(b.factory.IOStreams.Out, "deleting objects...")
if err := deleteAllObjects(client, b, ctx, b.name, ""); err != nil {
return err
}
err := client.DeleteBucket(ctx, b.name)
Expand Down Expand Up @@ -87,7 +88,7 @@ func (f *bucket) addFlags(flags *pflag.FlagSet) {
flags.BoolP("help", "h", false, msg.FLAG_HELP_DELETE_BUCKET)
}

func deleteAllObjects(client *api.Client, ctx context.Context, name, continuationToken string) error {
func deleteAllObjects(client *api.Client, b *bucket, ctx context.Context, name, continuationToken string) error {
objects, err := client.ListObject(ctx, name, &contracts.ListOptions{ContinuationToken: continuationToken})
if err != nil {
return err
Expand All @@ -99,7 +100,7 @@ func deleteAllObjects(client *api.Client, ctx context.Context, name, continuatio
return err
}
}
return deleteAllObjects(client, ctx, name, continuationToken)
return deleteAllObjects(client, b, ctx, name, continuationToken)
}
return nil
}
9 changes: 6 additions & 3 deletions pkg/schedule/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ func readFileSchedule() ([]Schedule, error) {
return schedules, nil
}

// @PatrickMenoti
// NOTE: preciso investigar o pq esse cara não consegui excluir a o item
// NOTE: preciso que o item sejá deletado do json assim q o delete é feito com sucesso
func ExecSchedules(factory *cmdutil.Factory) {
logger.Debug("Exec Schedules")
schedules, err := readFileSchedule()
Expand All @@ -103,15 +100,21 @@ func ExecSchedules(factory *cmdutil.Factory) {
return
}

scheds := []Schedule{}
for _, s := range schedules {
if CheckIf24HoursPassed(s.Time) {
if s.Kind == DELETE_BUCKET {
if err := TriggerDeleteBucket(factory, s.Name); err != nil {
logger.Debug("Event execution error", zap.Error(err))
scheds = append(scheds, s)
}
}
}
}

if err := createFileSchedule(scheds); err != nil {
logger.Debug("Scheduling error", zap.Error(err))
}
}

// CheckIf24HoursPassed Checks if the current time is before 24 hours after the time 's'.
Expand Down

0 comments on commit 99f8484

Please sign in to comment.