Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Treat server being down as client being offline #237

Closed
wants to merge 3 commits into from

Conversation

jhellar
Copy link
Contributor

@jhellar jhellar commented Feb 7, 2019

Description

This is implemented with custom RetryLink [1]. It has a queue for all incoming operations. When there is a new operation, it will try to forward it. On network error it will schedule next try. If there is operation with response from server, all operations in queue are force retried.

When creating RetryLink user can provide shouldRetry function to cancel retry if needed.

[1] https://github.com/aerogear/aerogear-js-sdk/pull/237/files#diff-46acc41354166331ff353344d6065e85

Checklist
  • added retryLink
  • unit tests
  • integration tests
  • documentation

Integration tests moved to separate jira - https://issues.jboss.org/browse/AEROGEAR-8521

@jhellar jhellar changed the title Treat server being down as client being offline [WIP] Treat server being down as client being offline Feb 7, 2019
@wtrocki
Copy link
Contributor

wtrocki commented Feb 7, 2019

@jhellar Is this another idea?

@jhellar
Copy link
Contributor Author

jhellar commented Feb 7, 2019

@wtrocki basically this is just adding retry link (custom one - to allow force retry) and slightly refactored offlineLink, so that code can be reused between those two links. Will add description.

@jhellar jhellar force-pushed the AEROGEAR-8447-2 branch 2 times, most recently from 328c60f to f0b1a82 Compare February 7, 2019 11:59
@jhellar jhellar requested a review from psturc February 8, 2019 09:57
@wtrocki wtrocki self-requested a review February 8, 2019 10:45
@@ -25,26 +21,18 @@ export const createClient = async (userConfig?: DataSyncConfig): Promise<Voyager
const clientConfig = extractConfig(userConfig);
const { cache } = await buildCachePersistence(clientConfig);

const httpLinks = await defaultHttpLinks(clientConfig);
let link = ApolloLink.from(httpLinks);
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. Thank you for taking that in. I wasn't really happy to see it here :)

let links: ApolloLink[] = [];
if (config.networkStatus) {
const offlineLink = new OfflineLink({
storage: config.storage,
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

const localDirectiveFilterLink = new LocalDirectiveFilterLink();
export const defaultHttpLinks = async (config: DataSyncConfig): Promise<ApolloLink> => {
let links: ApolloLink[] = [];
if (config.networkStatus) {
Copy link
Contributor

@wtrocki wtrocki Feb 8, 2019

Choose a reason for hiding this comment

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

IMHO this will be always non null. Is that because of typescript bragging about this being undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, this was because of typescript warning

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah there are two patterns to sort this:

  • Create separate interface with no optionals (too much IMHO)
  • use config.networkStatus as NetworkStatus to trick typescript.
  • if like here.

Let's leave it this way.

* - operation was completed (which could result in ID updates, i.e. new
* operations ready to be forwarded - see OfflineQueue class)
*/
export class OfflineLink extends ApolloLink {
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️ Man! Entire is very very clean and neatly drafted! Seriously good job.

}

/**
* This makes sure that pending mutations are force retried also
Copy link
Contributor

@wtrocki wtrocki Feb 8, 2019

Choose a reason for hiding this comment

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

[Question] pending mutations in this context means offline mutations in flight or every mutation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here it should be all mutations in this link that are waiting to be retried

import { RetriableOperation, shouldRetryFn } from "../offline/RetriableOperation";

export interface RetryLinkOptions {
shouldRetry?: shouldRetryFn;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is quite obvious but let's add just single node about this flag.

@wtrocki
Copy link
Contributor

wtrocki commented Feb 8, 2019

@jhellar I haven't seen such good code in very long time. Everything is so neatly drafted.
With every line of code I see that you clearly put a lots of thought into architecture of the link including arguments behaviour. This is true masterpiece and showcase of your amazing programming skills.
Proposed refactor brings very clean and extensible architecture. When reading this code I instantly see how things are organized.

Before I explode in all that excitement I will need to release development version of this and try test it with the app.

@wtrocki
Copy link
Contributor

wtrocki commented Feb 11, 2019

@jhellar I went and done quick testing, however this is quite big change so I would appreciate another person reviewing this. @psturc ?

@wtrocki
Copy link
Contributor

wtrocki commented Feb 11, 2019

As @jhellar is on holidays I'm taking over this task

@wtrocki wtrocki changed the title [WIP] Treat server being down as client being offline Treat server being down as client being offline Feb 12, 2019
@StephenCoady StephenCoady mentioned this pull request Feb 12, 2019
4 tasks
@wtrocki wtrocki closed this Feb 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants