2022-05-05 13:25:50 +00:00
|
|
|
// Copyright 2022 Cloudbase Solutions SRL
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
|
// not use this file except in compliance with the License. You may obtain
|
|
|
|
|
// a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
|
// License for the specific language governing permissions and limitations
|
|
|
|
|
// under the License.
|
|
|
|
|
|
2022-04-13 16:47:42 +00:00
|
|
|
package common
|
|
|
|
|
|
2022-04-29 23:43:37 +00:00
|
|
|
import (
|
2022-07-17 07:21:20 +00:00
|
|
|
"time"
|
2023-03-12 16:01:49 +02:00
|
|
|
|
|
|
|
|
"github.com/cloudbase/garm/params"
|
2022-04-29 23:43:37 +00:00
|
|
|
)
|
2022-04-23 13:05:40 +00:00
|
|
|
|
2022-04-27 16:56:28 +00:00
|
|
|
const (
|
2022-12-20 10:15:29 +01:00
|
|
|
PoolScaleDownInterval = 1 * time.Minute
|
2022-07-17 07:21:20 +00:00
|
|
|
PoolConsilitationInterval = 5 * time.Second
|
|
|
|
|
PoolReapTimeoutInterval = 5 * time.Minute
|
2022-10-12 21:45:07 +00:00
|
|
|
// Temporary tools download token is valid for 1 hour by default.
|
2023-06-30 13:38:19 +00:00
|
|
|
// There is no point in making an API call to get available tools, for every runner
|
|
|
|
|
// we spin up. We cache the tools for one minute. This should save us a lot of API calls
|
|
|
|
|
// in cases where we have a lot of runners spin up at the same time.
|
|
|
|
|
PoolToolUpdateInterval = 1 * time.Minute
|
2022-10-20 17:22:47 +03:00
|
|
|
|
2023-06-30 10:15:22 +00:00
|
|
|
// BackoffTimer is the time we wait before attempting to make another request
|
|
|
|
|
// to the github API.
|
|
|
|
|
BackoffTimer = 1 * time.Minute
|
2022-04-27 16:56:28 +00:00
|
|
|
)
|
|
|
|
|
|
2022-10-13 16:09:28 +00:00
|
|
|
//go:generate mockery --all
|
2022-04-23 13:05:40 +00:00
|
|
|
type PoolManager interface {
|
2022-06-29 16:23:01 +00:00
|
|
|
ID() string
|
2022-04-23 13:05:40 +00:00
|
|
|
WebhookSecret() string
|
2022-12-06 19:48:00 +00:00
|
|
|
GithubRunnerRegistrationToken() (string, error)
|
2022-04-23 13:05:40 +00:00
|
|
|
HandleWorkflowJob(job params.WorkflowJob) error
|
2022-05-04 16:27:24 +00:00
|
|
|
RefreshState(param params.UpdatePoolStateParams) error
|
2022-06-29 16:23:01 +00:00
|
|
|
ForceDeleteRunner(runner params.Instance) error
|
2022-05-02 17:55:29 +00:00
|
|
|
// AddPool(ctx context.Context, pool params.Pool) error
|
2022-04-26 20:29:58 +00:00
|
|
|
|
|
|
|
|
// PoolManager lifecycle functions. Start/stop pool.
|
|
|
|
|
Start() error
|
|
|
|
|
Stop() error
|
2022-10-20 17:22:47 +03:00
|
|
|
Status() params.PoolManagerStatus
|
2022-04-26 20:29:58 +00:00
|
|
|
Wait() error
|
|
|
|
|
}
|