Skip to content

Commit

Permalink
fix: log run now scrapes to job history
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed May 28, 2024
1 parent 1cfe1af commit 0148f1d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
8 changes: 6 additions & 2 deletions scrapers/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ func SyncScrapeJob(sc api.ScrapeContext) error {
return nil
}

func scheduleScraperJob(sc api.ScrapeContext) error {
func newScraperJob(sc api.ScrapeContext) *job.Job {
schedule, _ := lo.Coalesce(sc.ScrapeConfig().Spec.Schedule, DefaultSchedule)
j := &job.Job{
return &job.Job{
Name: "Scraper",
Context: sc.DutyContext().WithObject(sc.ScrapeConfig().ObjectMeta).WithAnyValue("scraper", sc.ScrapeConfig()),
Schedule: schedule,
Expand All @@ -159,6 +159,10 @@ func scheduleScraperJob(sc api.ScrapeContext) error {
return nil
},
}
}

func scheduleScraperJob(sc api.ScrapeContext) error {
j := newScraperJob(sc)

scrapeJobs.Store(sc.ScrapeConfig().GetPersistedID().String(), j)
if err := j.AddToScheduler(scrapeJobScheduler); err != nil {
Expand Down
16 changes: 7 additions & 9 deletions scrapers/run_now.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@ func RunNowHandler(c echo.Context) error {
}

ctx := api.DefaultContext.WithScrapeConfig(&configScraper)
results, err := RunScraper(ctx)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "failed to run scraper", err)
}

j := newScraperJob(ctx)
j.Run()
res := v1.RunNowResponse{
Total: len(results),
Errors: results.Errors(),
Total: j.LastJob.SuccessCount + j.LastJob.ErrorCount,
Errors: j.LastJob.Errors,
Failed: len(j.LastJob.Errors),
Success: j.LastJob.SuccessCount,
}
res.Failed = len(res.Errors)
res.Success = res.Total - res.Failed

return c.JSON(http.StatusOK, res)
}

0 comments on commit 0148f1d

Please sign in to comment.