Skip to content

Add environment variable to ignore services that are unreachable #15

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ The exported property contains an array of definitions, each linking a match to
- `options.gracePeriod`: Only send the response after a certain amount of time. This will group changes in the future.
- `options.ignoreFromSelf`: Don't inform about changes that originated from the microservice to be informed (based on the hostname).

### Ignoring errors:

Some errors can be ignored, the configuration for it is the following:

- `IGNORE_UNREACHABLE_SERVICES`: a comma-separated list of service names for which the unreachable error should be ignored

## Delta formats

The delta may be offered in multiple formats. Versions should match the exact string. Specify `options.resourceFormat` to indicate the specific resourceformat.
Expand Down
17 changes: 16 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ app.use( bodyParser.json( {
if( process.env["LOG_SERVER_CONFIGURATION"] )
console.log(JSON.stringify( services ));

let ignore_unreachable_services = (process.env["IGNORE_UNREACHABLE_SERVICES"]||"").split(',');

app.get( '/', function( req, res ) {
res.status(200);
res.send("Hello, delta notification is running");
Expand Down Expand Up @@ -53,8 +55,21 @@ async function informWatchers( changeSets, res, muCallIdTrail, muSessionId ){
console.log(`Checking if we want to send to ${entry.callback.url}`);

const matchSpec = entry.match;
let originFilteredChangeSets = [];

try {
originFilteredChangeSets = await filterMatchesForOrigin(changeSets, entry)
} catch (error) {
// When there's an error, this means the callback url could not be resolved and thus this should be handled
let hostname = (new URL(entry.callback.url)).hostname;
if (ignore_unreachable_services.filter(a => a === hostname).length === 0) {
console.error(`Error happened while filtering, ${hostname} couldn't be resolved`)
console.error(`please check that the service is running and the configuration file is correct`)
console.error(error)
}
return
}

const originFilteredChangeSets = await filterMatchesForOrigin( changeSets, entry );
if( process.env["DEBUG_TRIPLE_MATCHES_SPEC"] && entry.options.ignoreFromSelf )
console.log(`There are ${originFilteredChangeSets.length} changes sets not from ${hostnameForEntry( entry )}`);

Expand Down