This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Added start time for supporting restarts for fixed rate schedules #476
Merged
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9d9f407
Added race skip check
pmahindrakar-oss 8199f26
lint
pmahindrakar-oss 3db1d5f
Fixed unit tests
pmahindrakar-oss 62b7d74
Moved to integration test
pmahindrakar-oss 1583001
refactored integration test
pmahindrakar-oss 045085f
nit : rename to lastTime
pmahindrakar-oss 57ef179
nit : revert
pmahindrakar-oss a1b7913
lastTime -> lastExecTime
pmahindrakar-oss b06039b
integration test tag
pmahindrakar-oss 2c215a1
Merge remote-tracking branch 'origin' into fixedrate-issue
eapolinario File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
//go:build integration | ||
// +build integration | ||
|
||
package tests | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
||
"github.com/robfig/cron/v3" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
"golang.org/x/time/rate" | ||
|
||
adminModels "github.com/flyteorg/flyteadmin/pkg/repositories/models" | ||
"github.com/flyteorg/flyteadmin/pkg/runtime" | ||
scheduler "github.com/flyteorg/flyteadmin/scheduler/core" | ||
"github.com/flyteorg/flyteadmin/scheduler/executor/mocks" | ||
"github.com/flyteorg/flyteadmin/scheduler/repositories/models" | ||
"github.com/flyteorg/flyteadmin/scheduler/snapshoter" | ||
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" | ||
"github.com/flyteorg/flytestdlib/promutils" | ||
) | ||
|
||
func TestScheduleJob(t *testing.T) { | ||
ctx := context.Background() | ||
True := true | ||
now := time.Now() | ||
scheduleFixed := models.SchedulableEntity{ | ||
BaseModel: adminModels.BaseModel{ | ||
UpdatedAt: now, | ||
}, | ||
SchedulableEntityKey: models.SchedulableEntityKey{ | ||
Project: "project", | ||
Domain: "domain", | ||
Name: "fixed1", | ||
Version: "version1", | ||
}, | ||
FixedRateValue: 1, | ||
Unit: admin.FixedRateUnit_MINUTE, | ||
Active: &True, | ||
} | ||
t.Run("using schedule time", func(t *testing.T) { | ||
wg := &sync.WaitGroup{} | ||
wg.Add(1) | ||
timedFuncWithSchedule := func(jobCtx context.Context, schedule models.SchedulableEntity, scheduleTime time.Time) error { | ||
assert.Equal(t, now, scheduleTime) | ||
wg.Done() | ||
return nil | ||
} | ||
c := cron.New() | ||
configuration := runtime.NewConfigurationProvider() | ||
applicationConfiguration := configuration.ApplicationConfiguration().GetTopLevelConfig() | ||
schedulerScope := promutils.NewScope(applicationConfiguration.MetricsScope).NewSubScope("schedule_time") | ||
rateLimiter := rate.NewLimiter(1, 10) | ||
executor := new(mocks.Executor) | ||
snapshot := &snapshoter.SnapshotV1{} | ||
executor.OnExecuteMatch(mock.Anything, mock.Anything, mock.Anything).Return(nil) | ||
g := scheduler.NewGoCronScheduler(context.Background(), []models.SchedulableEntity{}, schedulerScope, snapshot, rateLimiter, executor, false) | ||
err := g.ScheduleJob(ctx, scheduleFixed, timedFuncWithSchedule, &now) | ||
c.Start() | ||
assert.NoError(t, err) | ||
select { | ||
case <-time.After(time.Minute * 2): | ||
assert.Fail(t, "timed job didn't get triggered") | ||
case <-wait(wg): | ||
break | ||
} | ||
}) | ||
|
||
t.Run("without schedule time", func(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry if I'm being dense - can you point out how this test differs than the one above? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check L62 & L90, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactored the test to remove redundant code which makes this test clearer |
||
wg := &sync.WaitGroup{} | ||
wg.Add(1) | ||
timedFuncWithSchedule := func(jobCtx context.Context, schedule models.SchedulableEntity, scheduleTime time.Time) error { | ||
assert.NotEqual(t, now, scheduleTime) | ||
wg.Done() | ||
return nil | ||
} | ||
c := cron.New() | ||
configuration := runtime.NewConfigurationProvider() | ||
applicationConfiguration := configuration.ApplicationConfiguration().GetTopLevelConfig() | ||
schedulerScope := promutils.NewScope(applicationConfiguration.MetricsScope).NewSubScope("schedule_time") | ||
rateLimiter := rate.NewLimiter(1, 10) | ||
executor := new(mocks.Executor) | ||
snapshot := &snapshoter.SnapshotV1{} | ||
executor.OnExecuteMatch(mock.Anything, mock.Anything, mock.Anything).Return(nil) | ||
g := scheduler.NewGoCronScheduler(context.Background(), []models.SchedulableEntity{}, schedulerScope, snapshot, rateLimiter, executor, false) | ||
err := g.ScheduleJob(ctx, scheduleFixed, timedFuncWithSchedule, nil) | ||
c.Start() | ||
assert.NoError(t, err) | ||
select { | ||
case <-time.After(time.Minute * 2): | ||
assert.Fail(t, "timed job didn't get triggered") | ||
case <-wait(wg): | ||
break | ||
} | ||
}) | ||
|
||
} | ||
|
||
func wait(wg *sync.WaitGroup) chan bool { | ||
ch := make(chan bool) | ||
go func() { | ||
wg.Wait() | ||
ch <- true | ||
}() | ||
return ch | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: should this field name change to job.lastExecTime too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing this would mean maintaining backward compat. I will clean this up when i next make change to this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, the JobStore will get loaded again after new version, so it will start using the new field after the restart, so we don't have to worry about backward compat.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, can you verify that there are indeed no problems on restart locally?