node.js - 使用 Node.js 在 App Engine 上长时间运行的进程
问题描述
我有一个可能需要一个多小时才能运行的 Node.js 网络爬虫。尝试在 App Engine 标准环境中运行时超时。部署它的最佳方式是什么?
此外,它触发了每天运行一次的 cron.yaml,它命中 Express 路由。有一个更好的方法吗?
这是代码的简化片段。我可以在本地运行它,并将其部署到 App Engine。dlLinkArray 中的少量链接运行良好。但是数量更大(数千),它似乎没有做任何事情。使用报告显示它运行了几秒钟。
const Storage = require('@google-cloud/storage');
const storage = new Storage();
function startDownload(){
dlLinkArray = [/*Array of objects with URL and Filename {link: 'http://source.com', filename: 'file123456'} */]; //About 10,000 links/files
var promises = [];
dlLinkArray.forEach(record =>{ //create array of nested promises
promises.push(
uploadFile(bucketName, record.link, record.filename)
.then((x) => {
if(x[1].name) //rename file from whatever is on the remote server to a usefull ID
return renameFile(bucketName, x[1].name, record.filename + ".pdf"); //renameFile uses storage.file.move to rename, returns a promise
else
return x;
})
);
});
return Promise.all(promises);
}
function uploadFile(bucketName, fileURL, reName) {
// Uploads a remove file to the Cloud Storage bucket
return storage
.bucket(bucketName)
.upload(fileURL, {
gzip: true,
metadata: {
cacheControl: 'public, max-age=31536000',
},
});
}
/*Express Route*/
app.get('/api/whatever/download', (req, res) => {
buckets2.startDownload().then(() => console.log("DONE"));
res.status(200).send("Download Started");
});
解决方案
我怀疑由于请求截止日期可能会出现问题。对于 App Engine 标准,默认设置为 60 秒。但是,如果您使用手动扩展,请求可以在标准环境中运行长达 24 小时。
推荐阅读
- javascript - 如何改变
- 至然后回到
- 具有新价值?
- javascript - 如何使 DataTables 根据需要从 Django 加载 AJAX 数据
- ruby-on-rails - Ruby 中的内部插件系统和模块(Rails 用作框架)
- google-cloud-platform - 根据 cidr 范围获取实例列表
- assembly - 为什么我输入查找值后我的案例表选择没有指向正确的地址?
- caching - Varnish:具有多个 IP 的后端(或使用其他东西)
- azure - 无法使用 Ansible 获取 Azure VM 私有 IP
- c# - 通过可枚举列表生成动态列 - Kendo Grid
- python-3.x - 如何使用 Selenium 和 Python 参考 HTML 中的文本定位元素
- c# - 如何从 Postman 将 XML 传递给 ASP.Net 核心中的 Web API