gocast icon indicating copy to clipboard operation
gocast copied to clipboard

Add Job and Action tracking for runner with GRPC notifications

Open Copilot opened this issue 3 months ago • 2 comments

Motivation and Context

Track runner job state in the database so the UI can display current runner activity. Previously, job execution was ephemeral with no persistence layer for monitoring.

Description

Adds database-backed job and action tracking with GRPC notifications from runner to gocast main instance.

New Models & DAO:

  • model/job.go - Job entity with unified WorkState type (created/running/completed/failed/cancelled) and timestamps
  • model/action.go - Action entity with its own table, referencing jobs via foreign key, storing action type as string, WorkState status, timestamps, and LastError for error tracking
  • dao/job.go - CRUD operations for both jobs and actions, queries by job ID, stream ID, runner hostname, active status

Protobuf Extensions:

  • Unified WorkState enum used by both jobs and actions
  • JobUpdateNotification message for job state changes (status only, no error field)
  • ActionUpdateNotification message for individual action state changes (uses string for action_type, includes last_error)

Runner Changes:

  • RunAction() sends separate job and action status notifications
  • Job notifications at creation, running state, and completion/failure/cancellation
  • Action notifications for each action start, completion, and failure (errors tracked at action level)
  • Action type is stored as plain string (e.g., "stream", "mk_vod", "check_vod")
  • Safe stream version enum conversion with fallback to STREAM_VERSION_UNSPECIFIED

Manager Changes:

  • handleJobUpdate() persists job state on notification receipt
  • handleActionUpdate() persists action state, creating new action records or updating existing ones
  • Single protoWorkStateToModel() converter for the unified WorkState type

Model Relations:

  • Runner.Jobs - foreign key relationship to active jobs
  • Stream.Jobs - foreign key relationship to associated jobs
  • Job.Actions - foreign key relationship to actions within a job
  • RunnerDao.GetAllWithJobs() - preloads active jobs for UI queries

Steps for Testing

Prerequisites:

  • Runner connected to gocast instance
  • Database access to verify jobs and actions tables
  1. Trigger a stream request to a runner
  2. Verify job record created in jobs table with status created
  3. Verify action records created in actions table for each action (stream, mk_vod, etc.)
  4. Observe job status transitions: createdrunningcompleted
  5. Observe action status transitions: runningcompleted for each action
  6. Cancel a stream mid-execution, verify job status becomes cancelled
  7. Force an action failure, verify action status becomes failed with last_error populated, and job status becomes failed

Screenshots

N/A - Backend changes only. UI integration pending separate PR.

Original prompt

Look at the current implementation of the runner with the actions and jobs.

Depict this functionality in the database and create GRPC notifications from the runner and the gocast main instance, such that the database always has the current state so I can show this in the UI


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot avatar Dec 05 '25 19:12 Copilot

@copilot I removed the lastError from the job. That is more of an action thing. Please clean up the notifications and notify about action updates where required.

joschahenningsen avatar Dec 05 '25 21:12 joschahenningsen

@copilot I removed the lastError from the job. That is more of an action thing. Please clean up the notifications and notify about action updates where required.

Removed LastError from the Job model and JobUpdateNotification protobuf in 750ad42. Errors are now tracked only at the action level via ActionUpdateNotification.

Copilot avatar Dec 05 '25 21:12 Copilot