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

Refactor schedule promises #161

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Changes from all 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
14 changes: 6 additions & 8 deletions internal/app/coroutines/schedulePromises.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,14 @@
// handle creating promise (schedule run) and updating schedule record.

return scheduler.NewCoroutine(metadata, func(c *scheduler.Coroutine[*t_aio.Completion, *t_aio.Submission]) {
crontime := schedule.NextRunTime
next, err := util.Next(crontime, schedule.Cron)
next, err := util.Next(schedule.NextRunTime, schedule.Cron)

Check warning on line 70 in internal/app/coroutines/schedulePromises.go

View check run for this annotation

Codecov / codecov/patch

internal/app/coroutines/schedulePromises.go#L70

Added line #L70 was not covered by tests
if err != nil {
slog.Error("failed to calculate next run time", "err", err)
return
}

id, err := generatePromiseId(schedule.PromiseId, map[string]string{
"timestamp": fmt.Sprintf("%d", crontime),
"timestamp": fmt.Sprintf("%d", schedule.NextRunTime),

Check warning on line 77 in internal/app/coroutines/schedulePromises.go

View check run for this annotation

Codecov / codecov/patch

internal/app/coroutines/schedulePromises.go#L77

Added line #L77 was not covered by tests
})
if err != nil {
slog.Error("failed to generate promise id", "err", err)
Expand All @@ -91,9 +90,8 @@

// calculate timeout for promise

now := c.Time()
state := promise.Pending
if schedule.PromiseTimeout+schedule.NextRunTime < now {
if c.Time() >= schedule.PromiseTimeout+schedule.NextRunTime {

Check warning on line 94 in internal/app/coroutines/schedulePromises.go

View check run for this annotation

Codecov / codecov/patch

internal/app/coroutines/schedulePromises.go#L94

Added line #L94 was not covered by tests
state = promise.Timedout
}

Expand All @@ -113,14 +111,14 @@
Tags: map[string]string{
"resonate:invocation": "true",
},
CreatedOn: crontime,
CreatedOn: schedule.NextRunTime,

Check warning on line 114 in internal/app/coroutines/schedulePromises.go

View check run for this annotation

Codecov / codecov/patch

internal/app/coroutines/schedulePromises.go#L114

Added line #L114 was not covered by tests
},
},
{
Kind: t_aio.UpdateSchedule,
UpdateSchedule: &t_aio.UpdateScheduleCommand{
Id: schedule.Id,
LastRunTime: &crontime,
LastRunTime: &schedule.NextRunTime,

Check warning on line 121 in internal/app/coroutines/schedulePromises.go

View check run for this annotation

Codecov / codecov/patch

internal/app/coroutines/schedulePromises.go#L121

Added line #L121 was not covered by tests
NextRunTime: next,
},
},
Expand Down Expand Up @@ -149,7 +147,7 @@
// helpers

func generatePromiseId(id string, vars map[string]string) (string, error) {
t := template.Must(template.New("promiseID").Parse(id))
t := template.Must(template.New("promiseId").Parse(id))

Check warning on line 150 in internal/app/coroutines/schedulePromises.go

View check run for this annotation

Codecov / codecov/patch

internal/app/coroutines/schedulePromises.go#L150

Added line #L150 was not covered by tests

var replaced strings.Builder
if err := t.Execute(&replaced, vars); err != nil {
Expand Down