Skip to content

Scala Client: add new jobWatcher() method for watcher API#4606

Merged
richscott merged 9 commits intoarmadaproject:masterfrom
richscott:rich/scala-client-watcher-api
Jan 26, 2026
Merged

Scala Client: add new jobWatcher() method for watcher API#4606
richscott merged 9 commits intoarmadaproject:masterfrom
richscott:rich/scala-client-watcher-api

Conversation

@richscott
Copy link
Member

@richscott richscott commented Jan 15, 2026

Add new jobWatcher(queue, jobset, lastMessage) method to ArmadaClient class, based on original logic in armada-spark repository.

Fill in implementation of watch() method in ArmadaClientSuite (test) EventMockServer. Clear out job, queue, and status maps (the backing store for the ArmadaMockServer) before running each test, to avoid test pollution.

Change from using .onComplete{..} idiom to Await.result(response, timeout) for more robust async testing behavior. Add watch support to testing mock server, add unit test for jobWatcher().

Fixes G-Research/spark#160

Add new jobWatcher(queue, jobset, lastMessage) method to ArmadaClient class,
based on original logic in armada-spark repository.

Fill in implementation of watch() method in ArmadaClientSuite (test)
EventMockServer. Clear out job, queue, and status maps (the backing store for
the ArmadaMockServer) before running each test, to avoid test pollution.

Change from using .onComplete{..} idiom to Await.result(response, timeout) for
more robust async testing behavior. Add test for jobWatcher(), verify that
expected events do arrive and in expected order.

Fixes G-Research/spark#160

Signed-off-by: Rich Scott <richscott@sent.com>
@richscott richscott self-assigned this Jan 15, 2026
@richscott richscott marked this pull request as draft January 15, 2026 00:06
@richscott richscott marked this pull request as ready for review January 16, 2026 17:12
matchingJobs.foreach { case (jobId, job) =>
// Check if job exists in statusMap
statusMap.get(jobId) match {
case Some(currentStatus) =>
Copy link
Collaborator

Choose a reason for hiding this comment

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

it doesn't appear as currentStatus is used anywhere. Shouldn't it be?

Also, it looks like you are emiting all the "usual" states simultaneously below. That seems odd. Don't we want the state emitted to depend on the current state?

Copy link
Member Author

@richscott richscott Jan 22, 2026

Choose a reason for hiding this comment

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

The currentStatus was just a placeholder for whatever get(jobId) returned, but it was ultimately just for determining if the given job ID really existed in the mock Armada. I have changed this to just use Map.contains() instead, which makes the code simpler, in commit 38306bb.

The state events are emitted sequentially (but not simultaneously, strictly-speaking), mostly just to verify that they are received by the iterator that jobWatcher(..) returns (and is used in armada-spark). The code just checks that all the events are received and in the order they were emitted. There's no higher-level state-transition logic in here for ordering, valid transition states, etc - that's elsewhere in Armada (outside the client), so it didn't seem necessary to try to reproduce and test that here.

Also, the e2e test in armada-spark appears to run successfully with a change of using the new jobWatcher() API method, but I will wait until this is merged and published out to the world.

Copy link
Collaborator

@GeorgeJahad GeorgeJahad Jan 22, 2026

Choose a reason for hiding this comment

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

I'm ok with it, but it is puzzling to see all events being emitted sequentially. I would add some of the comments from the explanation above explaining why it is the way it is.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍🏼 I've added an explanatory note in commit 9b0e647 - let me know if seems incomplete or confusing.

Replace Map.get(jobId) and check for optional return with just a
Map.contains(jobId) - we don't really care about the value (status),
just that it's a valid job ID.

Signed-off-by: Rich Scott <richscott@sent.com>
@richscott richscott requested a review from GeorgeJahad January 22, 2026 01:13
Copy link
Collaborator

@GeorgeJahad GeorgeJahad left a comment

Choose a reason for hiding this comment

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

lgtm, thanks @richscott !

@richscott richscott merged commit e8bf0e6 into armadaproject:master Jan 26, 2026
17 checks passed
@richscott richscott deleted the rich/scala-client-watcher-api branch January 26, 2026 16:28
Sigele pushed a commit to Sigele/armada that referenced this pull request Jan 30, 2026
…ect#4606)

Add new jobWatcher(queue, jobset, lastMessage) method to ArmadaClient
class, based on original logic in armada-spark repository.

Fill in implementation of watch() method in ArmadaClientSuite (test)
EventMockServer. Clear out job, queue, and status maps (the backing
store for the ArmadaMockServer) before running each test, to avoid test
pollution.

Change from using .onComplete{..} idiom to Await.result(response,
timeout) for more robust async testing behavior. Add `watch` support to
testing mock server, add unit test for jobWatcher().

Fixes G-Research/spark#160

---------

Signed-off-by: Rich Scott <richscott@sent.com>
Signed-off-by: Sigele Nickerson-Adams <sigele.nickerson-adams@nmc2.ai>
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.

The Armada client doesn't support the watcher api.

2 participants