Это мой скрипт узла:
const fs = require('fs');
const path = require('path');
const http = require('http');
// Overpass API URL and query
const overpassUrl = 'http://overpass-api.de/api/interpreter';
const query = '[out:xml][timeout:25];area(3600382313)->.searchArea;(nwr["landuse"="winter_sports"](area.searchArea););out geom;';
// Path for the temporary XML file
const xmlFilePath = path.join(__dirname, '../writable/ski/sknowed_calcs/aa_winter_sports_polygons.xml');
// Maximum number of retries
const maxRetries = 3;
// Function to fetch data
function fetchData(retries = 0) {
console.log(`Fetching data from Overpass API... (Attempt ${retries + 1}/${maxRetries})`);
// Encode query for URL
const url = `${overpassUrl}?data=${encodeURIComponent(query)}`;
// Send HTTP GET request with increased timeout
http.get(url, { timeout: 220000 }, (res) => {
res.setEncoding('utf8'); // Ensure response is treated as UTF-8
if (res.statusCode !== 200) {
console.error(`Failed to fetch data: ${res.statusCode} ${res.statusMessage}`);
res.resume(); // Consume response to free up memory
return;
}
let xmlData = '';
// Collect data chunks
res.on('data', (chunk) => {
xmlData += chunk;
});
// When the entire response is received
res.on('end', () => {
console.log('Data fetched successfully.');
// Ensure directory exists
fs.mkdirSync(path.dirname(xmlFilePath), { recursive: true });
// Save the XML response to a file with UTF-8 encoding
fs.writeFileSync(xmlFilePath, xmlData, 'utf8');
console.log(`XML file saved at ${xmlFilePath}`);
});
}).on('error', (error) => {
if (error.code === 'ETIMEDOUT' && retries < maxRetries - 1) {
console.error(`Request timed out. Retrying... (${retries + 1}/${maxRetries})`);
setTimeout(() => fetchData(retries + 1), 5000); // Retry after 5 seconds
} else {
console.error('Request failed:', error);
}
});
}
// Run the function
fetchData();
Вот какую ошибку я получаю:
Fetching data from Overpass API... (Attempt 1/3)
Fetching data from Overpass API... (Attempt 2/3)
Fetching data from Overpass API... (Attempt 3/3)
Request timed out. Retrying... (1/3)
Request timed out. Retrying... (2/3)
Request failed: AggregateError [ETIMEDOUT]:
at internalConnectMultiple (node:net
at internalConnectMultiple (node:net
at Timeout.internalConnectMultipleTimeout (node:net
at listOnTimeout (node:internal/timers:616:11)
at process.processTimers (node:internal/timers:549:7) {
code: 'ETIMEDOUT',
[errors]: [
Error: connect ETIMEDOUT 162.55.144.139:80
at createConnectionError (node:net
at Timeout.internalConnectMultipleTimeout (node:net
at listOnTimeout (node:internal/timers:616:11)
at process.processTimers (node:internal/timers:549:7) {
errno: -110,
code: 'ETIMEDOUT',
syscall: 'connect',
address: '162.55.144.139',
port: 80
},
Error: connect ENETUNREACH 2a01:4f8:261
at internalConnectMultiple (node:net
at Timeout.internalConnectMultipleTimeout (node:net
at listOnTimeout (node:internal/timers:616:11)
at process.processTimers (node:internal/timers:549:7) {
errno: -101,
code: 'ENETUNREACH',
syscall: 'connect',
address: '2a01:4f8:261
port: 80
},
Error: connect ETIMEDOUT 65.109.112.52:80
at createConnectionError (node:net
at Timeout.internalConnectMultipleTimeout (node:net
at listOnTimeout (node:internal/timers:616:11)
at process.processTimers (node:internal/timers:549:7) {
errno: -110,
code: 'ETIMEDOUT',
syscall: 'connect',
address: '65.109.112.52',
port: 80
},
Error: connect ENETUNREACH 2a01:4f9
at internalConnectMultiple (node:net
at Timeout.internalConnectMultipleTimeout (node:net
at listOnTimeout (node:internal/timers:616:11)
at process.processTimers (node:internal/timers:549:7) {
errno: -101,
code: 'ENETUNREACH',
syscall: 'connect',
address: '2a01:4f9
port: 80
}
]
}
А это мой скрипт codeigniter4, который никогда не дает сбоев:
public function osm_get_aa_winter_sports_polygons(){
helper('filesystem');
$query_get_skiArea = urlencode('[out:xml][timeout:25];area(3600382313)->.searchArea;(nwr["landuse"="winter_sports"](area.searchArea););out geom;');
$overpass = 'http://overpass-api.de/api/interpreter? ... et_skiArea;
$html = file_get_contents($overpass);
if (write_file(WRITEPATH. "/ski/osm_data/temp_aa_winter_sports_polygons.xml", $html)){
if (file_exists(WRITEPATH.'/ski/osm_data/aa_winter_sports_polygons.geojson')) {
$fileD = "aa_winter_sports_polygons.geojson.".date('m-d-Y-H-i-s'); //A e
@rename(WRITEPATH.'ski/osm_data/aa_winter_sports_polygons.geojson', WRITEPATH.'ski/'.$fileD);
}
exec('osmtogeojson '.WRITEPATH.'/ski/osm_data/temp_aa_winter_sports_polygons.xml > '.WRITEPATH.'/ski/osm_data/aa_winter_sports_polygons.geojson');
return redirect()->to('/admin/ski/osm_data')
->with('info', 'Success - aa_winter_sports_polygons data');
} else {
// dd($TaskResult);
$error = "something happened Harry";
return redirect()->back()
->with('errors', $error)
->with('warning', 'Invalid Data')
->withInput();
}
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... hat-am-i-d