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

Commit

Permalink
retry plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
sballesteros committed Nov 1, 2019
1 parent 7d7be93 commit 206f647
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,6 @@ extension/popup.js.map
deploy-env.private.sh
env.private.sh
*.private.sh

app.zip
service.zip
2 changes: 1 addition & 1 deletion deploy-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Deploy to https://rapid-prereview.azurewebsites.net/

./deploy-env.private.sh
./deploy-env.private.sh app

## See https://docs.microsoft.com/en-us/azure/app-service/deploy-zip

Expand Down
2 changes: 2 additions & 0 deletions deploy-service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## https://rapid-prereview-service.azurewebsites.net/

./deploy-env.private.sh service

## See https://docs.microsoft.com/en-us/azure/app-service/deploy-zip

zip -r service.zip *.json *.js dist/* src/* public/* views/* scripts/* test/*
Expand Down
14 changes: 13 additions & 1 deletion src/db/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,19 @@ export default class DB {
const cloudant = new Cloudant({
username,
password,
url: `${protocol}//${host}:${port}`
url: `${protocol}//${host}:${port}`,
maxAttempt: 5,
plugins: [
'cookieauth',
{
retry: {
retryErrors: true,
retryStatusCodes: [429, 500, 501, 502, 503, 504],
retryDelayMultiplier: 2,
retryInitialDelayMsecs: 500
}
}
]
});

this.cloudant = cloudant;
Expand Down
20 changes: 11 additions & 9 deletions src/service.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import http from 'http';
import express from 'express';
import DB from '../src/db/db';
import Feed from '../src/db/feed';
import DB from './db/db';
import Feed from './db/feed';
import {
setIntervalAsync,
clearIntervalAsync
} from './utils/set-interval-async';
import { PRODUCTION_DOMAIN } from './constants';

let lastSeq = null;
let lastErr = null;
let lastChangeErr = null;
let lastDateScoreUpdated = null;
let lastScoreErr = null;

const config = {
appRootUrl: PRODUCTION_DOMAIN,
Expand All @@ -22,6 +23,7 @@ const db = new DB(config);
const feed = new Feed(db);
feed.resume();
feed.on('error', err => {
lastChangeErr = err;
console.error(err);
});
feed.on('start', seq => {
Expand All @@ -30,28 +32,28 @@ feed.on('start', seq => {
feed.on('sync', seq => {
lastSeq = seq;
});
feed.on('error', err => {
lastErr = err;
});

const intervalId = setIntervalAsync(
() => {
lastDateScoreUpdated = new Date().toISOString();
return db.updateScores();
},
5 * 60 * 1000,
err => console.error(err)
err => {
lastScoreErr = err;
console.error(err);
}
);

const app = express();

app.get('/', (req, res, next) => {
res.json({ lastSeq, lastErr, lastDateScoreUpdated });
res.json({ lastSeq, lastChangeErr, lastScoreErr, lastDateScoreUpdated });
});

const server = http.createServer(app);

const port = process.env.PORT || 3000;
const port = process.env.PORT || 3001;
server.listen(port, () => {
console.log(`server listenning on port ${port}`);
});
Expand Down

0 comments on commit 206f647

Please sign in to comment.