92 lines
2.1 KiB
Go
92 lines
2.1 KiB
Go
/*
|
|
Copyright © 2026 Craig Williams <craig@avsdev.uk>
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
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
|
|
}
|