Short and single-letter names in application code become full words (tests keep theirs). Wrapped calls, signatures and composite literals put one item per line, and one-line function bodies are expanded. Exported names and groups of constants get doc comments, and comments refer to the renamed identifiers.
63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
package fetcher
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"log/slog"
|
|
"time"
|
|
|
|
"git.avsdev.uk/Go/job-search/internal/config"
|
|
"git.avsdev.uk/Go/job-search/internal/findatender"
|
|
"git.avsdev.uk/Go/job-search/internal/types"
|
|
"git.avsdev.uk/Go/job-search/internal/util"
|
|
)
|
|
|
|
// runFTSMock polls the mock Find a Tender server every configured interval
|
|
// until ctx is cancelled.
|
|
func runFTSMock(
|
|
ctx context.Context,
|
|
logger *slog.Logger,
|
|
conf *config.JobSearchConfig,
|
|
since time.Time,
|
|
) error {
|
|
worker := util.Worker{
|
|
Logger: logger,
|
|
Name: "FTSMock",
|
|
Interval: conf.Sources.FTSMock.Interval,
|
|
Task: func(ctx context.Context, since time.Time) error {
|
|
return fetchFTSMock(ctx, logger, conf, since)
|
|
},
|
|
}
|
|
return worker.Run(ctx, since)
|
|
}
|
|
|
|
// fetchFTSMock fetches everything updated since since from the mock Find a
|
|
// Tender server. Finding nothing returns ErrNoNewReleases, so the worker still
|
|
// moves its checkpoint on.
|
|
func fetchFTSMock(
|
|
ctx context.Context,
|
|
logger *slog.Logger,
|
|
conf *config.JobSearchConfig,
|
|
since time.Time,
|
|
) error {
|
|
opportunities, err := util.AwaitTask(ctx, func() ([]*types.Opportunity, error) {
|
|
findATender := findatender.New(
|
|
conf,
|
|
conf.Sources.FTSMock.APIRoot,
|
|
findatender.WithLogger(logger),
|
|
)
|
|
defer findATender.Shutdown()
|
|
return findATender.With(ctx).FetchAll(since, true)
|
|
})
|
|
if errors.Is(err, findatender.ErrNoReleases) {
|
|
return ErrNoNewReleases
|
|
}
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
logger.Info("fetched opportunities", "count", len(opportunities))
|
|
|
|
return nil
|
|
}
|