새 함수를 만드는 경우 Cloud Run의
콘솔 빠른 시작을 참고하세요.
제한 시간 후 실행
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
GCF 호출 시간이 초과된 후에 실행되어야 하지만 실행되지 않는 코드를 보여주는 샘플입니다.
코드 샘플
Go
Cloud Run Functions에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다.
자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.
Java
Cloud Run Functions에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다.
자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.
Node.js
Cloud Run Functions에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다.
자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.
Python
Cloud Run Functions에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다.
자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis page demonstrates code samples in Go, Java, Node.js, and Python that are designed to execute for two minutes, showcasing how Cloud Functions might time out before completion.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code examples highlight the potential for a function's execution to be interrupted by a timeout if the set duration is less than two minutes, as each sample includes a two-minute delay.\u003c/p\u003e\n"],["\u003cp\u003eThe samples use \u003ccode\u003etime.Sleep\u003c/code\u003e in Go, \u003ccode\u003eTimeUnit.MINUTES.sleep\u003c/code\u003e in Java, \u003ccode\u003esetTimeout\u003c/code\u003e in Node.js, and \u003ccode\u003etime.sleep\u003c/code\u003e in Python, to simulate a long-running process that could be cut short by a timeout.\u003c/p\u003e\n"],["\u003cp\u003eAuthentication for Cloud Run functions is achieved through setting up Application Default Credentials, with a link provided for further instructions on local development environment authentication.\u003c/p\u003e\n"],["\u003cp\u003eThe content directs users to the Google Cloud sample browser for further exploration of code samples across various Google Cloud products.\u003c/p\u003e\n"]]],[],null,["# Execution after timeout\n\nSample that demonstrates code that should (but won't) execute after a GCF call times out.\n\nCode sample\n-----------\n\n### Go\n\n\nTo authenticate to Cloud Run functions, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n // Package tips contains tips for writing Cloud Functions in Go.\n package tips\n\n import (\n \t\"fmt\"\n \t\"log\"\n \t\"net/http\"\n \t\"time\"\n\n \t\"github.com/GoogleCloudPlatform/functions-framework-go/functions\"\n )\n\n func init() {\n \tfunctions.HTTP(\"Timeout\", Timeout)\n }\n\n // Timeout sleeps for 2 minutes and may time out before finishing.\n func Timeout(w http.ResponseWriter, r *http.Request) {\n \tlog.Println(\"Function execution started...\")\n \ttime.Sleep(2 * time.Minute)\n \tlog.Println(\"Function completed!\")\n \tfmt.Fprintln(w, \"Function completed!\")\n }\n\n### Java\n\n\nTo authenticate to Cloud Run functions, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n package functions;\n\n import com.google.cloud.functions.HttpFunction;\n import com.google.cloud.functions.HttpRequest;\n import com.google.cloud.functions.HttpResponse;\n import java.io.BufferedWriter;\n import java.io.IOException;\n import java.util.concurrent.TimeUnit;\n import java.util.logging.Logger;\n\n public class AfterTimeout implements HttpFunction {\n private static final Logger logger = Logger.getLogger(AfterTimeout.class.getName());\n\n // Simple function to return \"Hello World\"\n @Override\n public void service(HttpRequest request, HttpResponse response)\n throws IOException, InterruptedException {\n logger.info(\"Function running...\");\n TimeUnit.MINUTES.sleep(2);\n\n // May not execute if function's timeout is \u003c2 minutes\n logger.info(\"Function completed!\");\n BufferedWriter writer = response.getWriter();\n writer.write(\"Function completed!\");\n }\n }\n\n### Node.js\n\n\nTo authenticate to Cloud Run functions, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n const functions = require('@google-cloud/functions-framework');\n\n /**\n * HTTP Cloud Function that may not completely\n * execute due to function execution timeout\n *\n * @param {Object} req Cloud Function request context.\n * @param {Object} res Cloud Function response context.\n */\n functions.http('afterTimeout', (req, res) =\u003e {\n setTimeout(() =\u003e {\n // May not execute if function's timeout is \u003c2 minutes\n console.log('Function running...');\n res.end();\n }, 120000); // 2 minute delay\n });\n\n### Python\n\n\nTo authenticate to Cloud Run functions, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n import time\n\n import functions_framework\n\n\n @functions_framework.http\n def timeout(request):\n print(\"Function running...\")\n time.sleep(120)\n\n # May not execute if function's timeout is \u003c2 minutes\n print(\"Function completed!\")\n return \"Function completed!\"\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=functions)."]]