Skip to content
This repository was archived by the owner on Oct 26, 2026. It is now read-only.

Create API for global progress listeners - #80

Merged
gselzer merged 5 commits into
mainfrom
scijava/scijava-ops-engine/global-progress
Oct 16, 2023
Merged

gselzer merged 5 commits into
mainfrom
scijava/scijava-ops-engine/global-progress

Conversation

@gselzer

@gselzer gselzer commented Jul 12, 2023 •

Copy link
Copy Markdown
Member

This PR adds API for introducing global progress listeners, in anticipation of end-users or external framework wanting to monitor progress without registering every Op.

Beyond the new global API, this PR also introduces additional changes needed to make Tasks more informative and robust. A list of the changes is provided below:

  • A description field is added to the Task class to make it clearer which Tasks describe a given execution. To support Ops, AbstractRichOp.toString() now provides a clear, more informative name.
  • To prevent multiple pings on completion, a safeguard was introduced to ensure that a Task completes only once.
  • Task updates now take a long defining the number of steps, instead of an int - this makes the step math more uniform.

@gselzer gselzer added the enhancement New feature or request label Jul 12, 2023
@gselzer
gselzer requested review from ctrueden and hinerm July 12, 2023 20:05
@gselzer gselzer self-assigned this Jul 12, 2023
@gselzer
gselzer marked this pull request as draft July 13, 2023 14:21
@gselzer
gselzer force-pushed the scijava/scijava-ops-engine/global-progress branch 4 times, most recently from 204eddb to 43df18b Compare July 14, 2023 15:56
@gselzer
gselzer marked this pull request as ready for review July 14, 2023 16:01

@ctrueden ctrueden left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The changes to Task to make it more robust are great!

But I'm not convinced about the Progress.addGlobalListener feature. What is a concrete use case where this is needed? I can't think of one.

Furthermore, the scijava-progress concept is very general, beyond only scijava-ops. You could in theory subscribe to updates to anything, right? So then this global listener thing really only listens to everything, with no way to narrow it to particular scopes. I feel like, if we are going to allow listeners that are broader than individual objects, we may want to allow listening to classes of objects, and then if you listen to Object you listen to everything. But now we are starting to reinvent scijava-common's org.scijava.event package, which already has that functionality in its event pub/sub model. Maybe it's worth considering if/how these two subsystems could be combined?

@gselzer

gselzer commented Jul 18, 2023

Copy link
Copy Markdown
Member Author

What is a concrete use case where this is needed? I can't think of one.

The original use case that I was thinking of was a Progress UI, allowing the user to keep track of Ops run in scripts and potentially also run graphically through a search bar. I don't know how you'd otherwise allow internal mechanisms to listen to progress - you'd probably need a callbacks mechanism...

The other use case here is convenience - the current API requires you to register the ProgressListener and the progressible Object before the Object starts providing progress updates. While the granularity is nice, there are two drawbacks on that approach:

  1. You cannot track the progress of executions performed directly from the OpBuilder call (like the one below), because the user does not have a handle on the Op.
ops.op("foo.bar").arity1().input(foo).output(bar).compute();
  1. You must register every Op with the ProgressListener, which will probably double the lines of code in your script.

It was this second use case that I encountered when I updated the tutorials, and made me want to add this functionality.

But now we are starting to reinvent scijava-common's org.scijava.event package, which already has that functionality in its event pub/sub model. Maybe it's worth considering if/how these two subsystems could be combined?

That's a good point, although I think we may still need the functionality to subscribe globally?

We might want to add a description to each Task, to tell them apart
if a single listener listens to multiple tasks
@gselzer
gselzer force-pushed the scijava/scijava-ops-engine/global-progress branch from 43df18b to c7f3a94 Compare October 16, 2023 19:44
It's nice to have a simple default, instead of always creating your own
@gselzer
gselzer merged commit 94f6a42 into main Oct 16, 2023
@gselzer

gselzer commented Oct 16, 2023

Copy link
Copy Markdown
Member Author

I merged these changes because I think it is an improvement in usability.

@ctrueden said:

The changes to Task to make it more robust are great!

But I'm not convinced about the Progress.addGlobalListener feature. What is a concrete use case where this is needed? I can't think of one.

Furthermore, the scijava-progress concept is very general, beyond only scijava-ops. You could in theory subscribe to updates to anything, right? So then this global listener thing really only listens to everything, with no way to narrow it to particular scopes. I feel like, if we are going to allow listeners that are broader than individual objects, we may want to allow listening to classes of objects, and then if you listen to Object you listen to everything. But now we are starting to reinvent scijava-common's org.scijava.event package, which already has that functionality in its event pub/sub model. Maybe it's worth considering if/how these two subsystems could be combined?

I think this is still a fair point, but I don't want to spend time right now thinking about it. I'd rather think about it when we have a need for the org.scijava.event package here.

@ctrueden
ctrueden deleted the scijava/scijava-ops-engine/global-progress branch October 17, 2023 07:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants