The crawl job's context ends on a cancel or at the job timeout. Storing the pages, links and issues now runs on a context detached from it with its own 10-minute bound, a timeout ends the crawl failed with a time-limit error, a LoadLimits failure falls back to the defaults, and a fetch cut short by the cancellation is recorded as canceled.
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package seo
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.golem15.com/golem15/sm-seo-plugin/classes"
|
|
"git.golem15.com/golem15/sm-seo-plugin/classes/crawl"
|
|
"git.golem15.com/golem15/summercms/modules/conga"
|
|
"git.golem15.com/golem15/summercms/modules/pact"
|
|
)
|
|
|
|
// Jobs registers the entry generation job (D-94) and the crawl job
|
|
// (golem15.seo.crawl, D-14) on conga. A crawl is not retried: a failed run
|
|
// records its error and keeps what it fetched.
|
|
func (p *Plugin) Jobs() []pact.Job {
|
|
return []pact.Job{
|
|
conga.Job(p.generateEntries, conga.MaxAttempts(3)),
|
|
conga.Job(p.crawl, conga.MaxAttempts(1), conga.Timeout(crawl.JobTimeout)),
|
|
}
|
|
}
|
|
|
|
// crawl runs one crawl job (golem15.seo.crawl).
|
|
func (p *Plugin) crawl(ctx context.Context, args crawl.CrawlArgs) error {
|
|
svc := p.Service()
|
|
if svc == nil {
|
|
return classes.ErrNotBooted
|
|
}
|
|
return crawl.Run(ctx, svc, args.CrawlID)
|
|
}
|
|
|
|
// generateEntries runs one generation job.
|
|
func (p *Plugin) generateEntries(ctx context.Context, args classes.GenerateEntriesArgs) error {
|
|
svc := p.Service()
|
|
if svc == nil {
|
|
return classes.ErrNotBooted
|
|
}
|
|
res, err := svc.GenerateEntries(ctx, args.Type)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
pluginLog.Info("golem15.seo: entries generated", "type", args.Type, "created", res.Created, "updated", res.Updated)
|
|
return nil
|
|
}
|
|
|
|
var _ pact.HasJobs = (*Plugin)(nil)
|