refs #5368 Added retryAttempts & retryTimeout
gitea/printnatura/pipeline/head This commit looks good
Details
gitea/printnatura/pipeline/head This commit looks good
Details
This commit is contained in:
parent
292866bcf9
commit
0cdf85541c
15
README.md
15
README.md
|
@ -19,7 +19,17 @@ Build
|
||||||
|
|
||||||
Create file named "config.local.yml" and put your private configuration:
|
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:
|
db:
|
||||||
host: localhost
|
host: localhost
|
||||||
port: 3306
|
port: 3306
|
||||||
|
@ -29,8 +39,7 @@ db:
|
||||||
salix:
|
salix:
|
||||||
url: http://localhost:3000
|
url: http://localhost:3000
|
||||||
user: user
|
user: user
|
||||||
reconnectTimeout: 30
|
password: password
|
||||||
refreshRate: 1000
|
|
||||||
```
|
```
|
||||||
## How to use
|
## How to use
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,8 @@ concurrency: 4
|
||||||
reconnectTimeout: 10
|
reconnectTimeout: 10
|
||||||
refreshRate: 1000
|
refreshRate: 1000
|
||||||
tmpDir: /dev/shm/printnatura
|
tmpDir: /dev/shm/printnatura
|
||||||
|
retryAttempts: 3
|
||||||
|
retryTimeout: 1500
|
||||||
db:
|
db:
|
||||||
host: localhost
|
host: localhost
|
||||||
port: 3306
|
port: 3306
|
||||||
|
|
|
@ -239,7 +239,7 @@ class PrintServer {
|
||||||
|
|
||||||
// Request
|
// Request
|
||||||
let pdfData;
|
let pdfData;
|
||||||
for (let attempts = 0; !pdfData && attempts < 3; attempts++) {
|
for (let attempts = 0; !pdfData && attempts < this.conf.retryAttempts; attempts++) {
|
||||||
try {
|
try {
|
||||||
const res = await this.api({
|
const res = await this.api({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
|
@ -250,28 +250,31 @@ class PrintServer {
|
||||||
pdfData = res.data;
|
pdfData = res.data;
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
if (err.name === 'AxiosError') {
|
if (err.name === 'AxiosError' && attempts < this.conf.retryAttempts - 1) {
|
||||||
const res = err.response;
|
const res = err.response;
|
||||||
switch(res.status) {
|
switch(res.status) {
|
||||||
case 401: // Unauthorized
|
case 401: // Unauthorized
|
||||||
await this.getToken();
|
await this.getToken();
|
||||||
break;
|
break;
|
||||||
case 502 || 504: // Bad Gateway & Gateway Timeout
|
case 502 || 504: // Bad Gateway & Gateway Timeout
|
||||||
|
await new Promise(
|
||||||
|
resolve => setTimeout(resolve, this.conf.retryTimeout));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
const resMessage = JSON.parse(res.data).error.message;
|
try {
|
||||||
const resErr = new Error(`${err.message}: ${resMessage}`);
|
const resMessage = JSON.parse(res.data).error.message;
|
||||||
resErr.stack = err.stack;
|
const resErr = new Error(`${err.message}: ${resMessage}`);
|
||||||
throw resErr;
|
resErr.stack = err.stack;
|
||||||
|
throw resErr;
|
||||||
|
} catch (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pdfData)
|
|
||||||
throw 'Could not get pdf from server'
|
|
||||||
|
|
||||||
// Save PDF to disk
|
// Save PDF to disk
|
||||||
const printer = jobData.printer;
|
const printer = jobData.printer;
|
||||||
const tmpPath = conf.tmpDir;
|
const tmpPath = conf.tmpDir;
|
||||||
|
|
Loading…
Reference in New Issue