feat(master): check the registry now from the service page (#35)
This commit is contained in:
@@ -139,6 +139,17 @@ func (p *Poller) Cycle(ctx context.Context) {
|
||||
p.log.Error("poll_list_failed", "error", err)
|
||||
return
|
||||
}
|
||||
stats := p.pollServices(ctx, svcs)
|
||||
p.log.Info("poll_cycle", "refs", stats.refs, "ok", stats.ok, "failed", stats.failed,
|
||||
"suggested", stats.suggested, "jobs", stats.jobs, "skipped", stats.skipped,
|
||||
"repos_listed", stats.reposListed, "tags_failed", stats.tagsFailed, "newer", stats.newer,
|
||||
"duration_ms", p.now().Sub(began).Milliseconds())
|
||||
}
|
||||
|
||||
// pollServices does the work of a cycle for svcs: it looks up every distinct
|
||||
// followed ref once, records the results and starts auto jobs, then syncs the
|
||||
// newer-tag suggestions of svcs.
|
||||
func (p *Poller) pollServices(ctx context.Context, svcs []model.Service) cycleStats {
|
||||
var stats cycleStats
|
||||
byRef := map[string][]model.Service{}
|
||||
var refs []string
|
||||
@@ -170,10 +181,41 @@ func (p *Poller) Cycle(ctx context.Context) {
|
||||
p.publishIfWrote(&stats)
|
||||
p.syncNewer(ctx, write, svcs, &stats)
|
||||
p.publishIfWrote(&stats)
|
||||
p.log.Info("poll_cycle", "refs", stats.refs, "ok", stats.ok, "failed", stats.failed,
|
||||
"suggested", stats.suggested, "jobs", stats.jobs, "skipped", stats.skipped,
|
||||
"repos_listed", stats.reposListed, "tags_failed", stats.tagsFailed, "newer", stats.newer,
|
||||
return stats
|
||||
}
|
||||
|
||||
// NotPolledError says a service cannot be checked against the registry.
|
||||
type NotPolledError struct{ Reason string }
|
||||
|
||||
func (e *NotPolledError) Error() string { return "not polled: " + e.Reason }
|
||||
|
||||
// PollService does what Cycle does, for the service id only: it looks up the
|
||||
// followed ref, records the digest, starts an auto job if one is wanted and
|
||||
// syncs the newer-tag suggestion. Other services that follow the same ref are
|
||||
// updated at the next cycle. It is safe to run while Run is running: the
|
||||
// unique index update_jobs_one_active prevents duplicate jobs. A registry
|
||||
// error is not returned; it is stored as last_poll_error, like in a cycle. It
|
||||
// returns the store's error when the service cannot be read, model.ErrNotFound
|
||||
// for a removed service, *NotPolledError when the service is not polled, and
|
||||
// ctx.Err() when ctx ended.
|
||||
func (p *Poller) PollService(ctx context.Context, id int64) error {
|
||||
began := p.now()
|
||||
svc, err := p.store.GetService(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if svc.RemovedAt != nil {
|
||||
return model.ErrNotFound
|
||||
}
|
||||
if r := SkipReason(svc); r != "" {
|
||||
return &NotPolledError{Reason: r}
|
||||
}
|
||||
stats := p.pollServices(ctx, []model.Service{svc})
|
||||
p.log.Info("poll_service", "service_id", id, "ref", jobs.FollowedRef(svc.ActualRef),
|
||||
"ok", stats.ok, "failed", stats.failed, "suggested", stats.suggested, "jobs", stats.jobs,
|
||||
"tags_failed", stats.tagsFailed, "newer", stats.newer,
|
||||
"duration_ms", p.now().Sub(began).Milliseconds())
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
// publishIfWrote tells the browsers to refresh if a phase of the cycle wrote
|
||||
|
||||
Reference in New Issue
Block a user