WIP - Add previous result in step functions, mocked functions#43
WIP - Add previous result in step functions, mocked functions#43arichiardi wants to merge 9 commits into
Conversation
988d5bf to
fc859cc
Compare
| inject (inject ctx)) | ||
| assoc-result-fn (cond | ||
| (let [ | ||
| ;; First step only gets the ctx, next ones receive last-result,ctx |
There was a problem hiding this comment.
Does this comment still apply?
|
|
||
| ;; on-exception | ||
| (fn [exception] | ||
| (fn [ctx exception] |
There was a problem hiding this comment.
I am going through all the breaking changes, this seems one.
Do we want to keep it? Is the context useful in case of exceptions? I remember back in the days we never needed it that's why it was not included in the signature.
There was a problem hiding this comment.
I like this signature more than anything because is consistent with all the callback functions signatures - the steps callbacks, and also the on-success callback, all have the same signature.
I also found very useful to be able to print the context when an exception happens.
And I can see it used when trying to recover from an error, maybe to repeat the flow from a certain step
| ;; on-success | ||
| (fn [ctx] | ||
| (handle-success (:github-things ctx)))) | ||
| (fn [ctx last-step-res] |
There was a problem hiding this comment.
This is another but we discussed it already and it seemed useful.
There was a problem hiding this comment.
yes. Not breaking in Clojurescript, but would be breaking in Clojure
| - [Optional] **on-anomaly** Function called in case of anomaly with the anomaly data itself. | ||
| - **on-exception** Function with the signature `(fn [ctx exception])` called with the context and an exception when any of the steps throws one. | ||
| - **on-success** Function with the signature `(fn [ctx last-step-result])` called with the context if all steps succeed, and the last step result. | ||
| - [Optional] **on-anomaly** Function with the signature `(fn [ctx anomaly])` called in case of anomaly with the context and the anomaly data itself. |
There was a problem hiding this comment.
Ok I see we added the context also to this one. Sorry don't want to be a pain but just want to understand if really necessary 😄
cc9d4a8 to
d0c6e41
Compare
1a87d13 to
8d71131
Compare
- Tests fixed accordingly
af6724a to
54df2b1
Compare
It can now be executed with yarn shadow-cljs compile simple-example and node dist/simple-example.js.
A couple of changes here. First of all the name specs in execute and core are now the same and both allow keyword and string for :name keys. Secondly, we refactor the specs so that including fonda.core.specs actually adds everything to the registry. Finally we fix the tests and issues that were detected with the change.
edc837c to
f6afbf4
Compare
In a nutshell, the main new features are:
on-success,on-error,on-start,on-completefor status reporting.:is-anomaly-error?attribute in the steps. The value is a function that would be called if the step returns an anomaly. If this function returns false, then the flow continues. This allows to break the circuit only with some anomalies.