Skip to content

Commit

Permalink
update dates of schedules which are updated daily
Browse files Browse the repository at this point in the history
  • Loading branch information
its-felix committed May 5, 2024
1 parent 9fbdd9c commit 47abf65
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions go/cron/action/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package action

import (
"context"
"encoding/json"
"errors"
"github.com/explore-flights/monorepo/go/common"
"time"
Expand Down Expand Up @@ -60,13 +59,19 @@ func (c *cronAction) Handle(ctx context.Context, params CronParams) (CronOutput,

switch params.LoadFlightSchedules.Schedule {
case "daily":
start := time.Now()
end := start.AddDate(0, 0, 7)

lfsInOut.Input.DateRanges = append(lfsInOut.Input.DateRanges, [2]common.LocalDate{
common.NewLocalDate(start),
common.NewLocalDate(end),
})
now := time.Now()
dates := []common.LocalDate{
common.NewLocalDate(now.AddDate(1, 0, 0)),
common.NewLocalDate(now.AddDate(0, 8, 0)),
common.NewLocalDate(now.AddDate(0, 6, 0)),
common.NewLocalDate(now.AddDate(0, 4, 0)),
common.NewLocalDate(now.AddDate(0, 2, 0)),
common.NewLocalDate(now.AddDate(0, 1, 0)),
}

for _, d := range dates {
lfsInOut.Input.DateRanges = append(lfsInOut.Input.DateRanges, [2]common.LocalDate{d, d})
}

default:
return output, errors.New("invalid schedule")
Expand Down Expand Up @@ -113,17 +118,3 @@ func (c *cronAction) Handle(ctx context.Context, params CronParams) (CronOutput,

return output, nil
}

func handle[IN any, OUT any](ctx context.Context, act Action[IN, OUT], params json.RawMessage) ([]byte, error) {
var input IN
if err := json.Unmarshal(params, &input); err != nil {
return nil, err
}

output, err := act.Handle(ctx, input)
if err != nil {
return nil, err
}

return json.Marshal(output)
}

0 comments on commit 47abf65

Please sign in to comment.