Files
job-search/internal/fetcher/worker_findatender.go
T
bwilliams 465358609a Naming, layout and comments: descriptive full-word names, one item per line in wrapped calls and literals, and doc comments on exported names
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.
2026-10-15 16:12:56 +01:00

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"
)
// runFindAOpportunity polls Find a Tender every configured interval until ctx
// is cancelled.
func runFindAOpportunity(
ctx context.Context,
logger *slog.Logger,
conf *config.JobSearchConfig,
since time.Time,
) error {
worker := util.Worker{
Logger: logger,
Name: "FindAOpportunity",
Interval: conf.Sources.FindATender.Interval,
Task: func(ctx context.Context, since time.Time) error {
return fetchFindAOpportunity(ctx, logger, conf, since)
},
}
return worker.Run(ctx, since)
}
// fetchFindAOpportunity fetches everything updated since since from Find a
// Tender. Finding nothing returns ErrNoNewReleases, so the worker still moves
// its checkpoint on.
func fetchFindAOpportunity(
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.FindATender.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
}