Skip to content

chore(server): structured logging Phase 2 — lib job manager/runner - #336

Merged
gkhngyk merged 1 commit into
mainfrom
feature/logging-phase2-lib-jobs
Jul 4, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
feature/logging-phase2-lib-jobs

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Fourth incremental slice of #303 (structured logging Phase 2). Migrates the console.* calls in lib/job-manager.js and lib/job-runner.js to the module-level pino logger. Both run outside the request lifecycle, so they use the module logger (not req.log) with structured fields instead of interpolated strings.

Files migrated (~16 calls):

  • job-manager.js (10): DB update failures → logger.error({ err, jobId }, …); cleanup summaries → logger.info({ count }, …)
  • job-runner.js (6): job failures → logger.error({ err, jobId }, …); cancellations + retry-scheduling → logger.info({ jobId, delayMs, attempt, attempts }, …)

Level mapping per the issue (console.error → error, console.log → info). Behaviour unchanged.

Related issue

Part of #303 (Phase 2 of #245), following #330, the routes slice, and the workers slice. lib/cloro-scraper.js is intentionally left out of this slice to avoid churn/conflicts with the query fan-out work (#332). server.js + middleware/index.js follow as the final slice.

Type of change

  • chore — Maintenance

How to test

  1. From server/: npm run lint, npm run format:check, npm run test (93 tests) all pass.
  2. grep -n "console\." server/src/lib/job-manager.js server/src/lib/job-runner.js returns nothing.
  3. A failing/cancelled/retried job now emits a structured JSON log line (error for failures, info for cancellation + retry scheduling with delayMs/attempt) instead of a console.* string.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • npm run lint passes (from server/)
  • npm run format:check passes (from server/)
  • Changes are focused — one concern per PR

Migrate the console.* calls in lib/job-manager.js and lib/job-runner.js
to the module-level pino logger. Both run outside the request lifecycle,
so they use the module logger with structured fields.

- job-manager.js (10): DB update failures → logger.error({ err, jobId });
  cleanup summaries → logger.info({ count })
- job-runner.js (6): job failures → logger.error({ err, jobId });
  cancellations + retry-scheduling → logger.info
  ({ jobId, delayMs, attempt, attempts })

Part of #303 (Phase 2 of #245). lib/cloro-scraper.js is intentionally
left out of this slice to avoid churn with the query fan-out work (#332);
server.js + middleware follow separately.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR is an incremental “structured logging Phase 2” slice that replaces console.* usage in background job orchestration (job-manager / job-runner) with the shared module-level pino logger (server/src/lib/logger.js), keeping behavior the same while producing leveled, structured JSON logs.

Changes:

  • Replace console.error in job-manager.js with logger.error({ err, jobId }, ...) for Supabase update/delete failures.
  • Replace console.log in job-manager.js cleanup paths with logger.info({ count }, ...).
  • Replace console.* in job-runner.js with structured logger.info/logger.error for cancellations, failures, and retry scheduling (including delayMs / attempt metadata).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
server/src/lib/job-runner.js Migrates job cancellation/failure/retry console logging to structured pino logger with job metadata fields.
server/src/lib/job-manager.js Migrates Supabase error logs and cleanup summary logs from console to structured pino logger.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gkhngyk
gkhngyk merged commit 4991e9f into main Jul 4, 2026
6 checks passed
@gkhngyk
gkhngyk deleted the feature/logging-phase2-lib-jobs branch July 4, 2026 14:36
gkhngyk added a commit that referenced this pull request Jul 6, 2026
…e) (#351)

Migrate the last console.* calls (lib/cloro-scraper.js) to the module-level
pino logger. This file was deliberately held back from the earlier slices
to avoid churn with the query fan-out work (#341, now merged).

- submit/poll per-task chatter (task submitted, completed, polling) →
  logger.debug({ taskId, scraperId, ... }); operational start → logger.info
  ({ taskType, scraperId, region }); failures/timeouts → logger.error
  ({ ..., status/reason }). Customer prompt text is no longer written to the
  submit log — taskType/scraperId/region identify the task instead.

Closes #303: every non-script console.* in server/src now routes through the
structured logger. Phase 2 of #245 is complete (parts: #330, #334, #335,
#336, #337, and this).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants