Repository navigation
feat(scheduler): expose existing job state event stream #1891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
milenkovicm
merged 9 commits into
apache:main
from
spiceai:upstream/job-state-broadcast-channel
Aug 5, 2026
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
719e604
feat: add a broadcast channel for job state event notifications
Jeadie 6ed1d3e
fix(core): add From<&JobId> for String so borrowed ids satisfy Into<S…
Jeadie 1323db6
fix(scheduler): address PR review feedback on job state broadcast cha…
Jeadie 9b69e8b
Merge branch 'main' into upstream/job-state-broadcast-channel
phillipleblanc 102fce2
docs: link JobStateEvent by absolute path so rustdoc resolves it
phillipleblanc 371146a
Merge branch 'main' into upstream/job-state-broadcast-channel
phillipleblanc c4b8cba
refactor(scheduler): expose existing job state event stream
phillipleblanc bd25aed
fix(scheduler): expose cluster state event stream
phillipleblanc aff9390
Merge branch 'main' into upstream/job-state-broadcast-channel
phillipleblanc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
ballista/scheduler/src/scheduler_server/job_state_event.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| //! Job state event notifications for subscribers. | ||
| //! | ||
| //! This module provides a broadcast-based notification system for job state changes. | ||
| //! Consumers can subscribe to receive notifications when jobs change state, avoiding | ||
| //! the need to poll for status updates. | ||
|
|
||
| use std::fmt; | ||
|
|
||
| /// Represents the current state of a job in the scheduler. | ||
| /// | ||
| /// This enum mirrors the possible states from the protobuf `job_status::Status` | ||
| /// but is designed to be lightweight for broadcasting. | ||
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
| pub enum JobState { | ||
| /// Job is queued and waiting to be scheduled. | ||
| Queued, | ||
| /// Job is currently running. | ||
| Running, | ||
| /// Job has completed successfully. | ||
| Completed, | ||
| /// Job has failed with an error message. | ||
| Failed(String), | ||
| /// Job was cancelled. | ||
| Cancelled, | ||
| } | ||
|
|
||
| impl fmt::Display for JobState { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| match self { | ||
| JobState::Queued => write!(f, "Queued"), | ||
| JobState::Running => write!(f, "Running"), | ||
| JobState::Completed => write!(f, "Completed"), | ||
| JobState::Failed(msg) => write!(f, "Failed: {}", msg), | ||
| JobState::Cancelled => write!(f, "Cancelled"), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Event emitted when a job's state changes. | ||
| /// | ||
| /// This struct is designed to be cloned and sent through a broadcast channel | ||
| /// to notify subscribers about job state changes. | ||
| #[derive(Debug, Clone)] | ||
| pub struct JobStateEvent { | ||
| /// The unique identifier of the job. | ||
| pub job_id: String, | ||
| /// The new state of the job. | ||
| pub state: JobState, | ||
| } | ||
|
|
||
| impl JobStateEvent { | ||
| /// Creates a new job state event. | ||
| pub fn new(job_id: impl Into<String>, state: JobState) -> Self { | ||
| Self { | ||
| job_id: job_id.into(), | ||
| state, | ||
| } | ||
| } | ||
|
|
||
| /// Creates a queued event for the given job. | ||
| pub fn queued(job_id: impl Into<String>) -> Self { | ||
| Self::new(job_id, JobState::Queued) | ||
| } | ||
|
|
||
| /// Creates a running event for the given job. | ||
| pub fn running(job_id: impl Into<String>) -> Self { | ||
| Self::new(job_id, JobState::Running) | ||
| } | ||
|
|
||
| /// Creates a completed event for the given job. | ||
| pub fn completed(job_id: impl Into<String>) -> Self { | ||
| Self::new(job_id, JobState::Completed) | ||
| } | ||
|
|
||
| /// Creates a failed event for the given job. | ||
| pub fn failed(job_id: impl Into<String>, error: impl Into<String>) -> Self { | ||
| Self::new(job_id, JobState::Failed(error.into())) | ||
| } | ||
|
|
||
| /// Creates a cancelled event for the given job. | ||
| pub fn cancelled(job_id: impl Into<String>) -> Self { | ||
| Self::new(job_id, JobState::Cancelled) | ||
| } | ||
| } | ||
|
|
||
| impl fmt::Display for JobStateEvent { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| write!( | ||
| f, | ||
| "JobStateEvent[job_id={}, state={}]", | ||
| self.job_id, self.state | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn test_job_state_event_creation() { | ||
| let event = JobStateEvent::queued("job-123"); | ||
| assert_eq!(event.job_id, "job-123"); | ||
| assert_eq!(event.state, JobState::Queued); | ||
|
|
||
| let event = JobStateEvent::running("job-123"); | ||
| assert_eq!(event.state, JobState::Running); | ||
|
|
||
| let event = JobStateEvent::completed("job-123"); | ||
| assert_eq!(event.state, JobState::Completed); | ||
|
|
||
| let event = JobStateEvent::failed("job-123", "Something went wrong"); | ||
| assert_eq!( | ||
| event.state, | ||
| JobState::Failed("Something went wrong".to_string()) | ||
| ); | ||
|
|
||
| let event = JobStateEvent::cancelled("job-123"); | ||
| assert_eq!(event.state, JobState::Cancelled); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_job_state_display() { | ||
| assert_eq!(JobState::Queued.to_string(), "Queued"); | ||
| assert_eq!(JobState::Running.to_string(), "Running"); | ||
| assert_eq!(JobState::Completed.to_string(), "Completed"); | ||
| assert_eq!( | ||
| JobState::Failed("error".to_string()).to_string(), | ||
| "Failed: error" | ||
| ); | ||
| assert_eq!(JobState::Cancelled.to_string(), "Cancelled"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 256 capacity is a sensible default. For a scheduler with high job throughput and a slow or briefly stalled subscriber, the buffer could fill and subscribers would start seeing
Lagged. Would it be worth pulling this intoSchedulerConfigso operators with heavier job rates can size it, keeping 256 as the default? Different deployments run very different workloads, so a fixed buffer may not fit everyone.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now configurable.