简体   繁体   English

删除Google Cloud Functions的tmp文件夹中的文件

[英]Deleting Files in tmp folder of Google Cloud Functions

I'm currently writing into files in a google cloud functions in my os.tmpdir folder. 我目前正在os.tmpdir文件夹中写入Google Cloud函数中的文件。 Now I know that each time the functions fires is slightly different and the tmp folder will never be the same between function calls (can't reference the same tmp folder twice). 现在,我知道每次函数触发都略有不同,并且两次函数调用之间的tmp文件夹将永远不会相同(无法两次引用同一个tmp文件夹)。 My question is whether or not I need to delete the file before the function finishes execution or if all the tmp memory is dereferenced automatically. 我的问题是在功能完成执行之前是否需要删除文件,或者是否自动取消了所有tmp内存的引用。

edit: When I write to os.tmpdir I can see the file when I look into the directory but on subsequent calls I see nothing. 编辑:当我写os.tmpdir时,当我查看目录时可以看到该文件,但是在随后的调用中什么也看不到。 I assume this means the file somehow no longer exists (unlikely) or I am looking in a different place. 我认为这意味着该文件以某种方式不再存在(不太可能),或者我正在其他位置查找。

below is the code I user to write the file. 下面是我用户写入文件的代码。

var wstream = fs.createWriteStream(os.tmpdir() + '/myOutput.txt');


wstream.write('Hello world!\n');
wstream.write('Another line\n');

wstream.end();      

wstream.on('finish', function () {
        console.log('file has been written');
        fs.readdir(os.tmpdir(), (err, files) => {
            console.log(files.length);
            files.forEach(file => {
                        console.log("Hey Again3", file);
                });
            })

edit 2: I've been running a few tests and the occurrence of a new system happens far more often than indicated in this question (I've observed every single time vs what I was told here that it would happen almost never). 编辑2:我已经进行了一些测试,并且新系统的发生比这个问题所指示的发生的频率要高得多(我每次都观察到,而在这里我被告知几乎永远不会发生)。 I also asked another question and received slightly conflicting advise from a different firebase employee that was more inline with the personal tests here: Can't Find file after having written to it in Google Cloud Functions 我还问了另一个问题,并从另一位Firebase员工那里收到了一些相互矛盾的建议,该建议更符合此处的个人测试: 在Google Cloud Functions中写入文件后找不到文件

The advise stays consistent but I not once observed have the exact same file system between multiple calls of a single function as indicated below. 建议保持一致,但我一次也没有观察到,在一次调用多个函数之间具有完全相同的文件系统,如下所示。

Firstly, the tmp folder identified by os.tmpdir() is always the same. 首先,由os.tmpdir()标识的tmp文件夹始终相同。 If you're observing something different, please clarify exactly what you're seeing. 如果您发现不同的地方,请明确说明您所看到的。

Secondly, you are not obliged to delete files out of tmpdir, but they occupy memory (it's a memory-based filesystem). 其次,您没有义务从tmpdir中删除文件,但是它们会占用内存(这是基于内存的文件系统)。 Leaving those files around makes your future function invocations more expensive, since you are paying for memory over time. 留下这些文件会使您将来的函数调用变得更加昂贵,因为随着时间的流逝您要为内存付费。 Also, you may risk running out of memory as you accumulate temp files. 同样,您可能会在累积临时文件时冒用尽内存的风险。 To be most efficient, you should always delete any files you create before the function finishes. 为了提高效率,您应始终在功能完成之前删除创建的所有文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 "如何为 Google Cloud Functions 删除 tmpfs 或 \/tmp 目录中的文件?" - How to delete files in tmpfs or /tmp directory for Google Cloud Functions? 如何在 Google Cloud Function 的 /tmp 文件夹中下载文件,然后将其上传到 Google Cloud Storage - How to download files in /tmp folder of Google Cloud Function and then upload it in Google Cloud Storage 通过Nodejs Firebase函数删除文件Google Cloud Storage时出现FetchError - FetchError while deleting files Google Cloud Storage via Nodejs Firebase functions 在Firebase Cloud Functions中的tmp目录中创建文件夹 - Creating Folders in the tmp Directory in Firebase Cloud Functions 使用Cloud Functions for Firebase和@ google-cloud / storage删除图像时出现问题 - issues deleting an image using Cloud Functions for Firebase and @google-cloud/storage 如何在不同文件中编写Google云功能? - How do I write Google cloud functions in different files? 无法使用Firebase功能删除Google Cloud Storage文件 - Cannot delete Google Cloud Storage files using Firebase Functions 在完成 nodeJS 后从 Google Cloud Functions 中的电子邮件中上传和解压缩 .zip 文件删除 .zip - Upload and unzip .zip file from E-Mail in Google Cloud Functions deleting .zip after completion nodeJS 从工件中删除旧文件后无法部署云功能 - Can't deploy cloud functions after deleting old files from artifacts Google Cloud Functions - 重试 - Google Cloud Functions - Retry
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM