Skip to content

Commit

Permalink
Merge pull request #8381 from Caprowni/master
Browse files Browse the repository at this point in the history
Add resource type check interval
  • Loading branch information
taylorsilva committed Apr 4, 2024
2 parents 2a7bb08 + d41e2fe commit 864bc19
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 3 deletions.
11 changes: 11 additions & 0 deletions atc/atccmd/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ type RunCommand struct {

GlobalResourceCheckTimeout time.Duration `long:"global-resource-check-timeout" default:"1h" description:"Time limit on checking for new versions of resources."`
ResourceCheckingInterval time.Duration `long:"resource-checking-interval" default:"1m" description:"Interval on which to check for new versions of resources."`
ResourceTypeCheckingInterval time.Duration `long:"resource-type-checking-interval" default:"1m" description:"Interval on which to check for new versions of resource types."`
ResourceWithWebhookCheckingInterval time.Duration `long:"resource-with-webhook-checking-interval" default:"1m" description:"Interval on which to check for new versions of resources that has webhook defined."`
MaxChecksPerSecond int `long:"max-checks-per-second" description:"Maximum number of checks that can be started per second. If not specified, this will be calculated as (# of resources)/(resource checking interval). -1 value will remove this maximum limit of checks per second."`
PausePipelinesAfter int `long:"pause-pipelines-after" default:"0" description:"The number of days after which a pipeline will be automatically paused if none of its jobs have run in more than the given number of days. A value of zero disables this component."`
Expand Down Expand Up @@ -539,6 +540,7 @@ func (cmd *RunCommand) Runner(positionalArguments []string) (ifrit.Runner, error
atc.EnableResourceCausality = cmd.FeatureFlags.EnableResourceCausality
atc.DefaultCheckInterval = cmd.ResourceCheckingInterval
atc.DefaultWebhookInterval = cmd.ResourceWithWebhookCheckingInterval
atc.DefaultResourceTypeInterval = cmd.ResourceTypeCheckingInterval

if cmd.BaseResourceTypeDefaults.Path() != "" {
content, err := os.ReadFile(cmd.BaseResourceTypeDefaults.Path())
Expand Down Expand Up @@ -1104,6 +1106,15 @@ func (cmd *RunCommand) backendComponents(
cmd.ResourceWithWebhookCheckingInterval = cmd.ResourceCheckingInterval
}

if cmd.ResourceTypeCheckingInterval < cmd.ResourceCheckingInterval {
logger.Info("update-resource-type-checking-interval",
lager.Data{
"oldValue": cmd.ResourceTypeCheckingInterval,
"newValue": cmd.ResourceCheckingInterval,
})
cmd.ResourceTypeCheckingInterval = cmd.ResourceCheckingInterval
}

components := []RunnableComponent{
{
Component: atc.Component{
Expand Down
2 changes: 2 additions & 0 deletions atc/builds/planner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1875,6 +1875,7 @@ var factoryTests = []PlannerTest{
func (test PlannerTest) Run(s *PlannerSuite) {
atc.DefaultCheckInterval = 1 * time.Minute
atc.DefaultWebhookInterval = 2 * time.Minute
atc.DefaultResourceTypeInterval = 3 * time.Minute

factory := builds.NewPlanner(atc.NewPlanFactory(0))

Expand Down Expand Up @@ -1913,6 +1914,7 @@ func (test PlannerTest) Run(s *PlannerSuite) {

atc.DefaultCheckInterval = 0
atc.DefaultWebhookInterval = 0
atc.DefaultResourceTypeInterval = 0
}

func (s *PlannerSuite) TestFactory() {
Expand Down
5 changes: 4 additions & 1 deletion atc/db/check_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ func NewCheckFactory(

func (c *checkFactory) TryCreateCheck(ctx context.Context, checkable Checkable, resourceTypes ResourceTypes, from atc.Version, manuallyTriggered bool, skipIntervalRecursively bool, toDB bool) (Build, bool, error) {
logger := lagerctx.FromContext(ctx)

sourceDefaults := atc.Source{}
parentType, found := resourceTypes.Parent(checkable)
if found {
Expand All @@ -105,6 +104,10 @@ func (c *checkFactory) TryCreateCheck(ctx context.Context, checkable Checkable,
interval = *checkable.CheckEvery()
}

if _, ok := checkable.(ResourceType); ok && checkable.CheckEvery() == nil {
interval.Interval = atc.DefaultResourceTypeInterval
}

skipInterval := manuallyTriggered
if !skipInterval && time.Now().Before(checkable.LastCheckEndTime().Add(interval.Interval)) {
// skip creating the check if its interval hasn't elapsed yet
Expand Down
6 changes: 4 additions & 2 deletions atc/db/check_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ var _ = Describe("CheckFactory", func() {
BeforeEach(func() {
atc.DefaultCheckInterval = defaultCheckInterval
atc.DefaultWebhookInterval = defaultWebhookCheckInterval
atc.DefaultResourceTypeInterval = defaultResourceTypeInterval
})

AfterEach(func() {
atc.DefaultCheckInterval = 0
atc.DefaultWebhookInterval = 0
atc.DefaultResourceTypeInterval = 0
})

Describe("TryCreateCheck", func() {
Expand Down Expand Up @@ -319,7 +321,7 @@ var _ = Describe("CheckFactory", func() {
Expect(fakeResourceType.CheckPlanCallCount()).To(Equal(1))
_, types, version, interval, defaults, _, _ := fakeResourceType.CheckPlanArgsForCall(0)
Expect(version).To(Equal(atc.Version{"from": "version"}))
Expect(interval.Interval).To(Equal(defaultCheckInterval))
Expect(interval.Interval).To(Equal(defaultResourceTypeInterval))
Expect(types).To(Equal(rts))
Expect(defaults).To(Equal(atc.Source{}))
})
Expand Down Expand Up @@ -348,7 +350,7 @@ var _ = Describe("CheckFactory", func() {
Expect(fakeResourceType.CheckPlanCallCount()).To(Equal(1))
_, types, version, interval, defaults, _, _ := fakeResourceType.CheckPlanArgsForCall(0)
Expect(version).To(Equal(atc.Version{"from": "version"}))
Expect(interval.Interval).To(Equal(defaultCheckInterval))
Expect(interval.Interval).To(Equal(defaultResourceTypeInterval))
Expect(types).To(Equal(rts))
Expect(defaults).To(Equal(atc.Source{}))
})
Expand Down
1 change: 1 addition & 0 deletions atc/db/db_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ var (

defaultCheckInterval = time.Minute
defaultWebhookCheckInterval = time.Hour
defaultResourceTypeInterval = time.Hour
defaultCheckTimeout = 5 * time.Minute

defaultBuildCreatedBy string
Expand Down
1 change: 1 addition & 0 deletions atc/resourcecheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "time"
var (
DefaultCheckInterval time.Duration
DefaultWebhookInterval time.Duration
DefaultResourceTypeInterval time.Duration
)

type CheckRequestBody struct {
Expand Down

0 comments on commit 864bc19

Please sign in to comment.