refs #5368 Added retryAttempts & retryTimeout
gitea/printnatura/pipeline/head This commit looks good Details

This commit is contained in:
Guillermo Bonet 2023-03-08 18:38:43 +01:00
parent 292866bcf9
commit 0cdf85541c
3 changed files with 26 additions and 12 deletions

View File

@ -19,7 +19,17 @@ Build
Create file named "config.local.yml" and put your private configuration:
```
debug: true
debug: false
log: true
dryPrint: false
keepFile: false
serverId: 1
concurrency: 4
reconnectTimeout: 10
refreshRate: 1000
tmpDir: /dev/shm/printnatura
retryAttempts: 3
retryTimeout: 1000
db:
host: localhost
port: 3306
@ -29,8 +39,7 @@ db:
salix:
url: http://localhost:3000
user: user
reconnectTimeout: 30
refreshRate: 1000
password: password
```
## How to use

View File

@ -7,6 +7,8 @@ concurrency: 4
reconnectTimeout: 10
refreshRate: 1000
tmpDir: /dev/shm/printnatura
retryAttempts: 3
retryTimeout: 1500
db:
host: localhost
port: 3306

View File

@ -239,7 +239,7 @@ class PrintServer {
// Request
let pdfData;
for (let attempts = 0; !pdfData && attempts < 3; attempts++) {
for (let attempts = 0; !pdfData && attempts < this.conf.retryAttempts; attempts++) {
try {
const res = await this.api({
method: 'get',
@ -250,28 +250,31 @@ class PrintServer {
pdfData = res.data;
}
catch (err) {
if (err.name === 'AxiosError') {
if (err.name === 'AxiosError' && attempts < this.conf.retryAttempts - 1) {
const res = err.response;
switch(res.status) {
case 401: // Unauthorized
await this.getToken();
break;
case 502 || 504: // Bad Gateway & Gateway Timeout
await new Promise(
resolve => setTimeout(resolve, this.conf.retryTimeout));
break;
default:
const resMessage = JSON.parse(res.data).error.message;
const resErr = new Error(`${err.message}: ${resMessage}`);
resErr.stack = err.stack;
throw resErr;
try {
const resMessage = JSON.parse(res.data).error.message;
const resErr = new Error(`${err.message}: ${resMessage}`);
resErr.stack = err.stack;
throw resErr;
} catch (err) {
throw err;
}
}
} else
throw err;
}
}
if (!pdfData)
throw 'Could not get pdf from server'
// Save PDF to disk
const printer = jobData.printer;
const tmpPath = conf.tmpDir;