Files
job-search/internal/findATender/findATender.go
T
bwilliams 005b335371 Minor fixes:
- Fixed function name typo
- Fetcher/Run now returns a combination of errors if any workers error out. All other workers are ordered to shutdown if any one does error out
- findATender now returns a pointer instead of an instance from New
2026-10-09 18:26:10 +01:00

75 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/types"
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
}
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,
) ([]*types.Opportunity, error) {
releases, err := ft.fetchOnce(RequestOptions{
Since: since,
AllowRateLimit: allowRateLimit,
})
if err != nil {
return nil, err
}
return Convert(releases), nil
}
func (ft *FindATender) FetchAll(
since time.Time,
allowRateLimit bool,
) ([]*types.Opportunity, error) {
releases, err := ft.fetchAll(RequestOptions{
Since: since,
AllowRateLimit: allowRateLimit,
})
if err != nil {
return nil, err
}
return Convert(releases), nil
}