Closed kwin closed 3 years ago
Another option is to make all the current methods cancelCurrentExecution
, advanceCurrentExecution
and getCurrentExecution
return an Optional
being empty, in case there is no current execution. This won't be backwards-compatible, though....
Calling any of the current
methods should always throw an exception if there isn't an execution - asking for something that is current, that doesn't exist is an exceptional state and thus the exception. (Really any response from the API that's not 20? is an exceptional state which makes sense).
I'm not entirely sure how a convenience method would benefit any of the callers of the library. Adding such a method would not eliminate the need for consumers to be cognizant of, and handle the case where, the API call returns false (none running) and then the subsequent call to start the execution fails because during the intermediary time, something else started the pipeline.
I'm not opposed to having such a feature available in the API, but it doesn't remove the need for the library consumers to handle race conditions appropriately for their business cases
Exceptions should be for exceptional cases. Not having an execution is not an exceptional case, therefore there must be a way to figure out if there is a current execution without having to deal with the overhead of exceptions. Compare also with https://stackoverflow.com/questions/729379/why-not-use-exceptions-as-regular-flow-of-control#:~:text=Exceptions%20are%20basically%20non%2Dlocal,are%20written%20for%20programmers%20first).
IMO - Not having a current
execution when you ask for the current execution is the definition of an exceptional case.
How to figure out if there is a current execution? IMHO there is no API for that without relying on exceptions!
Consider this use case: In my Jenkins Pipeline I want to stop an already running execution (if there is one) and trigger a new one.
I'm not apposed to providing an API to check whether or not if the pipeline is running.
But by the nature of the system, these calls do have race conditions and thus are exceptional cases. Your use case is related to #25 - The API is non-blocking, but that doesn't mean the desired action is complete when the response is returned.
Providing an API to query "Is there an current execution?" Can be done.
Providing an API to perform the logic: "Stop any current execution on this pipeline, and start a new one" - Cannot be handled by this library. See issue #25.
Even the other direction: Starting a new pipeline, and immediately asking for the currentExecution can result in an exception because the request to start the pipeline has been successfully submitted, but it has not actively started. This is an exceptional case and needs to be indicated to the consumer. It is also the most effective and efficient way for the library to handle different scenarios and allow consumers to determine their steps depending on their context.
All methods exposed by
CloudManagerApi
related to current executions of a pipeline with a given id throw an exception in case no execution is running. It would be handy to have a method likehasCurrentExecution(...)
which doesn't rely on exceptions (due to the overhead of dealing with exception)