★ wanayoo — archive 1999 https://github.com/commercetools/commercetools-sync-java/issues/107Nouvelle recherche | Portail wanayoo
Skip to content
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

Refactor callback concept #107

Closed
heshamMassoud opened this issue Sep 21, 2017 · 10 comments
Closed

Refactor callback concept #107

heshamMassoud opened this issue Sep 21, 2017 · 10 comments

Comments

@heshamMassoud
Copy link
Contributor

@heshamMassoud heshamMassoud commented Sep 21, 2017 •

Callback should support returning boolean. This is to support the use case of continuing or not when one update action building fails. Should the entire product/category still be synced with the rest of the successful update actions or not.

Right now, if one update action fails, the callback would be applied but the rest of the update actions for the product would still be applied.

  1. Change name warningCallBack -> validationCallback (or draftValidationCB, dataValidationCB, syncValidationCb, etc..)
    • Extend param list to be: (Enum ErrorType, String errorMessage, T oldResource, S newDraft)
  2. Change name of errorCallback -> ctpErrorCalback
    • Extend param list to be: (String errorMessage, T oldResource, S newDraft, Throwable exception)
  3. Need to think about the continue on errors concept..
  4. Also see issue: #50 and

Update

Referencing TODOs from #336 (comment):

  • Difference between events causing errorCallback and warningCallback should be clearly defined and documented.
  • errorCallback exceptions should not be nullable. It should always have an exception object. (Think about removing the errorMessage String)
@heshamMassoud heshamMassoud modified the milestones: backlog, 1.0.0-M2 Sep 21, 2017
@heshamMassoud heshamMassoud modified the milestones: 1.0.0-M2, 1.0.0-M3-beta Sep 29, 2017
@heshamMassoud heshamMassoud added this to To Do in 1.0.0-M2 Sep 29, 2017
@heshamMassoud heshamMassoud moved this from To Do to In Progress in 1.0.0-M2 Oct 1, 2017
@heshamMassoud heshamMassoud self-assigned this Oct 1, 2017
@heshamMassoud heshamMassoud changed the title Callback should support returning boolean Refactor callback concept Oct 12, 2017
@heshamMassoud heshamMassoud modified the milestones: 1.0.0-M2-beta-2, 1.0.0-M3 Oct 12, 2017
@heshamMassoud heshamMassoud added this to To Do in 1.0.0-M3 Oct 12, 2017
@heshamMassoud heshamMassoud removed this from In Progress in 1.0.0-M2 Oct 12, 2017
@heshamMassoud heshamMassoud removed this from To Do in 1.0.0-M3 Oct 24, 2017
@heshamMassoud heshamMassoud modified the milestones: 1.0.0-M3, 1.0.0-M4 Oct 24, 2017
@heshamMassoud heshamMassoud modified the milestones: 1.0.0-M10, 1.0.0-M11 Feb 14, 2018
@heshamMassoud heshamMassoud added this to To Do in 1.0.0-M11 Feb 14, 2018
@heshamMassoud heshamMassoud modified the milestones: 1.0.0-M11, 1.0.0-M12 Mar 6, 2018
@heshamMassoud heshamMassoud removed this from To Do in 1.0.0-M11 Mar 6, 2018
@heshamMassoud heshamMassoud added this to To do in 1.0.0-M13 Mar 8, 2018
@heshamMassoud heshamMassoud removed this from the 1.0.0-M13 milestone Sep 5, 2018
@butenkor
Copy link
Member

@butenkor butenkor commented Nov 28, 2018 •

Extend param list to be: (Enum ErrorType, String errorMessage, T oldResource, S newDraft)

Suggestion as discussed (exception would be a subtype of SyncException and also contain detailed error message):

(SyncException se, T oldResource, S newDraft)

rest looks good :)

@jarzynp
Copy link
Contributor

@jarzynp jarzynp commented Nov 29, 2018

Hi @heshamMassoud
If you agree I'd like to implement this - maybe it will be sufficient enough (instead of #336), but have some questions:

  1. Return value

Callback should support returning boolean

Does this apply only to the error callback or to warning one as well?

  1. Update action

This is to support the use case of continuing or not when one update action building fails. Should the entire product/category still be synced with the rest of the successful update actions or not.

What update action really means? For example: ProductType:

  • when creating we are using ProductTypeCreateCommand which accepts ProductTypeDraft as parameter
  • when updating we are using ProductTypeUpdateCommand which accepts versioned product type and list of UpdateAction<>
    When there will be error during processing on target side, all successful operations up to this moment will be reverted - it doesn't matter if it happened during creation or updating and exception will be returned - so there is no possibility to continue with UpdateAction<> which were not processed yet.
    But sync process will be continued with another resource draft (if any). Does the update action in this context mean a single Resource update (a batch unit)? Please clarify that as the update action can be misleading (possibly confused with the UpdateAction class).

By resource draft I understand one list item passed to this methods: BaseSync#sync(@Nonnull final List<T> resourceDrafts) or BaseSync#process(@Nonnull final List<T> resourceDrafts)

  1. Parameter order
    What should be order of parameters oldResource and newResourceDraft:
    a. proposed: T oldResource, S newDraft
    b. consistent with beforeUpdateCallback: S newDraft, T oldResource

  2. SyncException
    What is SyncException mentioned by @butenkor ? Is this a new class which is not yet in sources (some branch maybe) or it has to be created? If the latter what it should contain?

  3. Exception and message
    Maybe it would be good to replace parameters String errorMessage and Throwable exception by some aggregation class, SyncException maybe? Maybe context related data (oldResource, newDraft) should be also in SyncException?

@heshamMassoud
Copy link
Contributor Author

@heshamMassoud heshamMassoud commented Nov 29, 2018 •

Hi, @jarzynp, of course! that would be great :)

  1. Does this apply only to the error callback or to warning one as well?

I think It would be useful if we return boolean on both callbacks. So the user is more flexible to choose when to stop the sync process (even if on a warning use case). WDYT? (cc: @butenkor)

  1. This is to support the use case of continuing or not when one update action building fails. Should the entire product/category still be synced with the rest of the successful update actions or not. What update action really means? For example: ProductType:

Sorry, the issue was described in a rush. Let me try to rephrase a bit:

The errorCallback could be triggered at many places during syncing each productTypeDraft, this includes:

  1. While building enum value update actions (e.g. removeEnumValues, addPlainEnumValue, etc..) for a productType's attribute that will be used later in an update request. If the supplied enum in the productTypeDraft has duplicate keys.
  2. While issuing an update request to CTP due to a 400, or even a 5xx after retrying, etc..
  3. While issuing a create request to CTP due to a 400, or even a 5xx after retrying, etc..

It could be that the user would want to selectively choose if he/she wants to continue the sync process or actually continue after such error occurs.

But sync process will be continued with another resource draft (if any). Does the update action in this context mean a single Resource update (a batch unit)? Please clarify that as the update action can be misleading (possibly confused with the UpdateAction class).

By resource draft I understand one list item passed to this methods: BaseSync#sync(@nonnull final List resourceDrafts) or BaseSync#process(@nonnull final List resourceDrafts)

Yes, by that we mean with one resource draft error. For example one productTypeDraft.

  1. What should be order of parameters oldResource and newResourceDraft:
    a. proposed: T oldResource, S newDraft
    b. consistent with beforeUpdateCallback: S newDraft, T oldResource

Good point. In that sense, b sounds more user-friendly. But all the update action utils have the ordering of *a 😢 WDYT? (cc: @butenkor)

  1. & 5. What is SyncException mentioned by @butenkor ? Is this a new class which is not yet in sources (some branch maybe) or it has to be created? If the latter what it should contain?

No, it doesn't exist yet. It is a proposal to have a kind of a parent Throwable type that has a cause (which could be anything e.g. SphereException from the platform, or BuildUpdateException from the library, etc..

@butenkor
Copy link
Member

@butenkor butenkor commented Dec 6, 2018

So the user is more flexible to choose when to stop the sync process

I am not sure if return value is necessary as the caller can throw own exception to break sync execution - if needed. If callback is defined in the same class where the sync instance is created then one could also catch own error an eventually also access/log sync statistics from existing sync instance.

b sounds more user-friendly

indeed :)

@jarzynp
Copy link
Contributor

@jarzynp jarzynp commented Dec 14, 2018

Ok, so what's the final decision for return value?

  1. Return value for both callbacks
  2. Return value only for errorCallback
  3. Return value only for warningCallback
  4. No return value for both callbacks
@butenkor
Copy link
Member

@butenkor butenkor commented Dec 17, 2018

Hi @jarzynp,

here is polished version of my previous comment :)

Ok, so what's the final decision for return value?

For now we do not have clear business use-case so let's just take option 4 and apply other suggested changes:

As discussed, an exception would be a subtype of SyncException and also contain detailed error message.

errorCallback:

  • (SyncException se, T oldResource, S newDraft, Optional<List<UpdateAction<T>>>)
  • Let's also keep old name: errorCallback

warningCallback

  • (SyncException se, T oldResource, S newDraft)
  • Let's also keep old name: warningCallback

@heshamMassoud You agree?

@heshamMassoud
Copy link
Contributor Author

@heshamMassoud heshamMassoud commented Dec 17, 2018

@jarzynp Yes, I agree with @butenkor. We can leave the the return value / continue on errors concept as another issue/feature 😉

jarzynp pushed a commit to ambsoft/commercetools-sync-java that referenced this issue Dec 28, 2018
@jarzynp
Copy link
Contributor

@jarzynp jarzynp commented Dec 28, 2018

Hi,

PR ready for review: #367

Happy New Year! :)

@heshamMassoud heshamMassoud modified the milestones: Next Steps, 2.0.0 Jan 29, 2019
jarzynp pushed a commit to ambsoft/commercetools-sync-java that referenced this issue Apr 9, 2019
jarzynp pushed a commit to ambsoft/commercetools-sync-java that referenced this issue Jul 16, 2019
- QuadConsumer
- Optional<List -> List
- order in error/warning properties
- reverted formatting changes for ProductVariantPriceUpdateActionUtil
- renaming CallBack -> Callback in InventorySyncOptions

- rename CallBack -> Callback in BaseSyncOptions
@heshamMassoud heshamMassoud modified the milestones: 2.0.0, Next Steps Jan 24, 2020
@heshamMassoud
Copy link
Contributor Author

@heshamMassoud heshamMassoud commented Jan 24, 2020

Besides checking existing PR comments and addressing conflicts, make sure that we use a context object which is propagated everywhere needed down the update actions utils, so that we can get the old and new resources deep down the method chain without the need of applying workarounds (e.g. the generic types of the util class).

The idea is to propagate to the callback the whole resource (new or old) and not just failed sub resource (e.g. assets, prices, etc..)

ahalberkamp added a commit that referenced this issue Aug 20, 2020
* #107: refactor callback concept

* #107: further review fixes

* #107: review fixes:
- QuadConsumer
- Optional<List -> List
- order in error/warning properties
- reverted formatting changes for ProductVariantPriceUpdateActionUtil
- renaming CallBack -> Callback in InventorySyncOptions

- rename CallBack -> Callback in BaseSyncOptions

* Fix unit tests.

* Fix integration tests.

* #522:Add products to call back

* 107:Publish changes to codebase.

* 107:Fix checkstyle issues.

* 107:Add proper parameter to test.

* 107:Remove unused null check.

* Add additional test.

* Add final.

* Add new test.

* 107:Add new test.

* Add new test.

* fix checkstyle issue.

* 107:Fix findbug issue.

* Adjust javadoc.

* Fix findbug issue.

* Fix failing test.

* Remove unneeded type definition.

* Update src/main/java/com/commercetools/sync/categories/helpers/CategoryAssetActionFactory.java

Co-authored-by: Lam Tran <lam.tran@commercetools.de>

* Remove whitespace.

* Update src/main/java/com/commercetools/sync/categories/utils/CategoryAssetUpdateActionUtils.java

Co-authored-by: Lam Tran <lam.tran@commercetools.de>

* Update src/main/java/com/commercetools/sync/categories/utils/CategoryAssetUpdateActionUtils.java

Co-authored-by: Lam Tran <lam.tran@commercetools.de>

* Change interface method.

* Update src/main/java/com/commercetools/sync/commons/utils/AssetsUpdateActionUtils.java

Co-authored-by: Lam Tran <lam.tran@commercetools.de>

* Fix typo

* Add spaces.

* Overload method.

* Update src/main/java/com/commercetools/sync/producttypes/ProductTypeSync.java

Co-authored-by: Lam Tran <lam.tran@commercetools.de>

* Update src/main/java/com/commercetools/sync/producttypes/ProductTypeSync.java

Co-authored-by: Lam Tran <lam.tran@commercetools.de>

* Fix failing test number.

* Use variable.

* Rename variable.

* Adjust javadoc.

* Refactor handle error method.

* Update src/test/java/com/commercetools/sync/inventories/InventorySyncTest.java

Co-authored-by: Lam Tran <lam.tran@commercetools.de>

* Rename method.

* pass null instead optional.

* Update src/test/java/com/commercetools/sync/producttypes/ProductTypeSyncTest.java

Co-authored-by: Lam Tran <lam.tran@commercetools.de>

* Rename test

* Add propert comment.

* Modifiy interface.

* Remove whitespace.

* Change typedef of AssetActionFactory.

* Generalize interface.

* Fix example.

* Update javadoc

* rewrite javadoc.

* Fix checkstyle issues.

* Improve documentation.

* Change formatting.

* Add Release notes.

* Update Versions.

* Adjust template.

Co-authored-by: piotr <p.jarzynski@ambsoft.pl>
Co-authored-by: aoz <bilmuhahmet@gmail.com>
Co-authored-by: andreas Halberkamp <andreas.halberkamp@commercetools.de>
@ahmetoz ahmetoz closed this Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.