-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GAPI-24749: major documentation update, cache and retry rework
- Loading branch information
1 parent
e73ca48
commit b666d20
Showing
44 changed files
with
556 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,72 @@ | ||
--- | ||
title: Mollitia - API - Circuit | ||
--- | ||
# Circuit | ||
|
||
Circuit | ||
The `Circuit` is the container of your **Resilience** logic. | ||
|
||
## Usage | ||
|
||
``` javascript | ||
// Imports the library | ||
const { Circuit } = require('mollitia'); | ||
// Creates a circuit | ||
const pgCircuit = new Circuit({ | ||
name: 'PostgreSQL Operations' | ||
}); | ||
// Call operations | ||
await circuit.fn(sqlRequest).execute('SELECT * FROM Mollitia;'); | ||
``` | ||
|
||
That is not really useful, as by default, the circuit just calls your method, with your arguments. | ||
|
||
## Modules | ||
|
||
Adding modules to your circuit will add logic to it, but be careful, **the module ordering have an importance!** | ||
Let's see with an example: | ||
|
||
``` javascript | ||
// Imports needed components | ||
const { Circuit, Retry, Timeout } = require('mollitia'); | ||
// Creates a Retry Module | ||
const retry = new Retry({ | ||
attempts: 2, // Will retry two times | ||
}); | ||
const timeout = new Timeout({ | ||
delay: 500, // Will timeout after 500ms | ||
}); | ||
// Creates Circuits | ||
const retryWithTimeout = new Circuit({ | ||
options: { | ||
modules: [retry, timeout] | ||
} | ||
}); | ||
const timeoutRetries = new Circuit({ | ||
options: { | ||
modules: [timeout, retry] | ||
} | ||
}); | ||
``` | ||
|
||
### Retry with Timeout | ||
|
||
Here is what will happen with the first circuit: | ||
|
||
``` javascript | ||
retryWithTimeout.fn(failureAsync).execute('dummy', 1000) // Launches the failureAsync method, that will return "dummy", and will take 1000ms to complete | ||
// Attempt #1: The function times out (1000 > 500) - Launches First Retry | ||
// Attempt #2: The function times out (1000 > 500) - Launches Second Retry | ||
// Attempt #3: The function times out (1000 > 500) - Fails with TimeoutError | ||
``` | ||
|
||
### Timeout Retries | ||
|
||
Here is what will happen with the second circuit: | ||
|
||
``` javascript | ||
timeoutRetries.fn(failureAsync).execute('dummy', 1000) // Exactly like before | ||
// Attempt #1: The function times out (1000 > 500) - Fails with TimeoutError | ||
``` | ||
|
||
Because the [Timeout](/api/module/timeout) module is set before the [Retry](/api/module/retry) module, the timeout is global for all attempts. | ||
Therefore, the Circuit does have time to make a retry, it times out before. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,46 @@ | ||
--- | ||
title: Mollitia - API - Create a module | ||
--- | ||
# Create a module | ||
|
||
Create a module | ||
Creating a new module is easy, you can extends the base **Module** class and use it like so: | ||
|
||
``` javascript | ||
// Imports the library | ||
const { Circuit, Module } = require('mollitia'); | ||
|
||
// Creates a class | ||
class UselessModule extends Module { | ||
// Should implement the constructor, and call super(options) | ||
constructor (options) { | ||
super(options); | ||
this.message = options.message; | ||
} | ||
// Should implement the execute method | ||
async execute (circuit, promise, ...params) { | ||
// circuit: Circuit being executed | ||
// promise: The Circuit Function being used | ||
// params[]: The list of parameters being used | ||
console.info(`${circuit.name} - ${this.message}`); // That's some useful stuff | ||
return promise(...params); // This just executes normally the method | ||
} | ||
} | ||
|
||
// Let's use our new module | ||
const circuit = new Circuit({ | ||
name: 'UselessCircuit', | ||
options: { | ||
modules: [ | ||
new UselessModule({ | ||
message: 'Hello World!' | ||
}) | ||
] | ||
} | ||
}); | ||
|
||
// Execute the circuit | ||
circuit.fn(() => { return; }).execute(); | ||
|
||
// Logs will be: | ||
// UselessCircuit - Hello World! | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,23 @@ | ||
--- | ||
title: Mollitia - API - Create a plugin | ||
--- | ||
# Create a plugin | ||
|
||
Create a plugin | ||
Creating a plugin is similar as [creating a module](/api/create-module), you should implement the **Plugin** interface: | ||
|
||
``` javascript | ||
// Imports the library | ||
const Mollitia = require('mollitia'); | ||
|
||
// Creates a class | ||
class UselessPlugin implements Mollitia.Plugin { | ||
// Called when a circuit is created | ||
onCircuitCreate (circuit, options) { | ||
// Feel free to modify the circuit behavior, and add properties to it | ||
} | ||
// Called when a module is created | ||
onModuleCreate (module, options) { | ||
// Feel free to modify the module behavior, and add properties to it | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.