Files
job-search/internal/findATender/findATender.go
T

76 lines
1.4 KiB
Go

package findATender
import (
"context"
"time"
"git.avsdev.uk/Go/job-search/internal/config"
"git.avsdev.uk/Go/job-search/internal/findATender/ocds"
resty "resty.dev/v3"
)
type FindATender struct {
httpClient *resty.Client
config *config.JobSearchConfig
apiRoot string
ctx context.Context
}
func New(conf *config.JobSearchConfig, apiRoot string) FindATender {
ft := FindATender{
config: conf,
apiRoot: apiRoot,
}
ft.httpClient = resty.New().
SetTimeout(60 * time.Duration(time.Second)).
SetRetryCount(1)
return ft
}
func (ft *FindATender) ReloadConfig(conf *config.JobSearchConfig) {
ft.config = conf
// TODO: any reloading required for configuration change handling
}
func (ft *FindATender) With(ctx context.Context) *FindATender {
if ctx == nil {
return ft
}
copied := *ft
copied.ctx = ctx
return &copied
}
func (ft *FindATender) Shutdown() {
ft.httpClient.Close()
}
func (ft *FindATender) FetchOnce(
since time.Time,
allowRateLimit bool,
) ([]ocds.Release, error) {
reqs, err := ft.fetchOnce(RequestOptions{
Since: since,
AllowRateLimit: allowRateLimit,
})
if err != nil {
return nil, err
}
return reqs, nil
}
func (ft *FindATender) FetchAll(
since time.Time,
allowRateLimit bool,
) ([]ocds.Release, error) {
reqs, err := ft.fetchAll(RequestOptions{
Since: since,
AllowRateLimit: allowRateLimit,
})
if err != nil {
return nil, err
}
return reqs, nil
}