透過 App Engine 應用程式建立工作

教學課程:使用 Cloud Tasks 觸發 Cloud Functions 的 App Engine 應用程式。

深入探索

如需包含這個程式碼範例的詳細說明文件,請參閱下列內容:

程式碼範例

Node.js

如要瞭解如何安裝及使用 Cloud Tasks 的用戶端程式庫,請參閱「Cloud Tasks 用戶端程式庫」。

如要向 Cloud Tasks 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。

app.post('/send-email', (req, res) => {
  // Set the task payload to the form submission.
  const {to_name, from_name, to_email, date} = req.body;
  const payload = {to_name, from_name, to_email};

  createHttpTaskWithToken(
    process.env.GOOGLE_CLOUD_PROJECT,
    QUEUE_NAME,
    QUEUE_LOCATION,
    FUNCTION_URL,
    SERVICE_ACCOUNT_EMAIL,
    payload,
    date
  );

  res.status(202).send('📫 Your postcard is in the mail! 💌');
});

後續步驟

如要搜尋及篩選其他 Google Cloud 產品的程式碼範例,請參閱Google Cloud 範例瀏覽器