th triggers

ເອີ້ນ Container ຫຼື Function ຕາມເວລາ (Cron) ຫຼື ທຸກຂໍ້ຄວາມທີ່ເຂົ້າ Queue

ກ່ຽວກັບ

A trigger sends an HTTP POST to a path of a Container or function without a visitor. It works for internal-only and token-protected services too, and wakes a service that scaled to zero.

  • Cron (--schedule): five fields, minute hour day month weekday, or @hourly, @daily, @weekly, @monthly, in --time-zone (default Asia/Bangkok). The body is --body, or JSON naming the run.
  • Queue (--queue): every message of a queue in the same Project, --concurrency at once (1–10), as JSON {"trigger","queue","message":{"id","body","attributes","sentAt","receives"}}. A 2xx answer deletes the message; anything else hands it out again after 10 seconds, doubling up to 10 minutes, and past the queue’s max receives it moves to its dead-letter queue.

Trigger requests carry X-TH-Trigger, X-TH-Trigger-Id and X-TH-Trigger-Kind headers (queue ones also X-TH-Trigger-Queue, X-TH-Trigger-Message-Id and X-TH-Trigger-Receives). The public address removes these headers from visitors’ requests, so your app can trust them. A service has at most 20 triggers.

ວິທີເຮັດ

Run a task every night

Shell
th triggers create nightly --service api --schedule "0 3 * * *" --path /tasks/cleanup
th triggers run nightly --service api
th triggers list --service api

On Git Bash, start the path with // or set MSYS_NO_PATHCONV=1: Git Bash turns arguments that start with / into Windows paths.

Process a queue

Shell
th queue create jobs --max-receives 5 --dead-letter jobs-dlq
th triggers create worker --service api --queue jobs --concurrency 5 --path /jobs
th queue send jobs '{"order": 1042}'

ຄຳສັ່ງ

ຄຳສັ່ງຄຳອະທິບາຍ
th triggers createCreates a trigger that POSTs to the service without a visitor.
th triggers listLists the triggers of a Container or function.
th triggers updateChanges a trigger; flags left out keep their value.
th triggers runFires a cron trigger once now, outside its schedule.
th triggers pausePaused a trigger.
th triggers resumeResumed a trigger.
th triggers deleteDeletes a trigger.

th triggers create

Creates a trigger that POSTs to the service without a visitor.

ຮູບແບບຄຳສັ່ງ

Shell
th triggers create NAME --service NAME (--schedule CRON | --queue QUEUE) [flags]
--schedule "0 3 * * *"   on a cron schedule (minute hour day month weekday)
--queue jobs             for every message of a Queue of the same Project;
                         a 2xx answer deletes the message, anything else
                         hands it out again later (and past the queue's
                         max receives, to its dead-letter queue)

ຕົວຢ່າງ

Shell
th triggers create nightly --service api --schedule "0 3 * * *" --path /tasks/nightly
Shell
th triggers create worker --service api --queue jobs --concurrency 5 --path /jobs

ອາກິວເມັນຕາມຕຳແໜ່ງ

ຊື່ຄຳອະທິບາຍ
NAMEຕ້ອງໃສ່The trigger’s name: lowercase letters, digits and -, unique on its service.
CRONຕ້ອງໃສ່

ພາຣາມິເຕີ

ຊື່ປະເພດຄ່າເລີ່ມຕົ້ນຄຳອະທິບາຍ
--serviceຕ້ອງໃສ່ຂໍ້ຄວາມContainer or function the trigger calls
--scheduleຂໍ້ຄວາມCron schedule, e.g. "*/15 * * * *" or @daily
--time-zoneຂໍ້ຄວາມAsia/BangkokTime zone of the schedule
--bodyຂໍ້ຄວາມJSON naming the runRequest body of a cron run
--queueຂໍ້ຄວາມQueue whose messages call the service
--concurrencyຕົວເລກ1Queue messages handed over at once, 1-10
--pathຂໍ້ຄວາມ/Path the platform POSTs to

ພາຣາມິເຕີທົ່ວໄປ

ຄຳສັ່ງນີ້ຮັບ ພາຣາມິເຕີທົ່ວໄປ ໄດ້ນຳ: --project, --region, --endpoint, --format, --quiet

ກັບຂຶ້ນເທິງ ↑

th triggers list

Lists the triggers of a Container or function.

ຮູບແບບຄຳສັ່ງ

Shell
th triggers list --service NAME

ພາຣາມິເຕີ

ຊື່ປະເພດຄ່າເລີ່ມຕົ້ນຄຳອະທິບາຍ
--serviceຕ້ອງໃສ່ຂໍ້ຄວາມContainer or function

ພາຣາມິເຕີທົ່ວໄປ

ຄຳສັ່ງນີ້ຮັບ ພາຣາມິເຕີທົ່ວໄປ ໄດ້ນຳ: --project, --region, --endpoint, --format, --quiet

ກັບຂຶ້ນເທິງ ↑

th triggers update

Changes a trigger; flags left out keep their value.

ຮູບແບບຄຳສັ່ງ

Shell
th triggers update NAME --service NAME [--schedule CRON] [--time-zone TZ] [--body BODY]
    [--queue QUEUE] [--concurrency N] [--path PATH] [--rename NEW]

A trigger's kind does not change.

ອາກິວເມັນຕາມຕຳແໜ່ງ

ຊື່ຄຳອະທິບາຍ
NAMEຕ້ອງໃສ່The trigger’s name: lowercase letters, digits and -, unique on its service.

ພາຣາມິເຕີ

ຊື່ປະເພດຄ່າເລີ່ມຕົ້ນຄຳອະທິບາຍ
--serviceຕ້ອງໃສ່ຂໍ້ຄວາມContainer or function the trigger calls
--scheduleຂໍ້ຄວາມCron schedule, e.g. "*/15 * * * *" or @daily
--time-zoneຂໍ້ຄວາມAsia/BangkokTime zone of the schedule
--bodyຂໍ້ຄວາມJSON naming the runRequest body of a cron run
--queueຂໍ້ຄວາມQueue whose messages call the service
--concurrencyຕົວເລກ1Queue messages handed over at once, 1-10
--pathຂໍ້ຄວາມ/Path the platform POSTs to
--renameຂໍ້ຄວາມNew name

ພາຣາມິເຕີທົ່ວໄປ

ຄຳສັ່ງນີ້ຮັບ ພາຣາມິເຕີທົ່ວໄປ ໄດ້ນຳ: --project, --region, --endpoint, --format, --quiet

ກັບຂຶ້ນເທິງ ↑

th triggers run

Fires a cron trigger once now, outside its schedule.

ຮູບແບບຄຳສັ່ງ

Shell
th triggers run NAME --service NAME

See the result with th triggers list.

ອາກິວເມັນຕາມຕຳແໜ່ງ

ຊື່ຄຳອະທິບາຍ
NAMEຕ້ອງໃສ່The trigger’s name: lowercase letters, digits and -, unique on its service.

ພາຣາມິເຕີ

ຊື່ປະເພດຄ່າເລີ່ມຕົ້ນຄຳອະທິບາຍ
--serviceຕ້ອງໃສ່ຂໍ້ຄວາມContainer or function

ພາຣາມິເຕີທົ່ວໄປ

ຄຳສັ່ງນີ້ຮັບ ພາຣາມິເຕີທົ່ວໄປ ໄດ້ນຳ: --project, --region, --endpoint, --format, --quiet

ກັບຂຶ້ນເທິງ ↑

th triggers pause

Paused a trigger.

ຮູບແບບຄຳສັ່ງ

Shell
th triggers pause NAME --service NAME

ອາກິວເມັນຕາມຕຳແໜ່ງ

ຊື່ຄຳອະທິບາຍ
NAMEຕ້ອງໃສ່The trigger’s name: lowercase letters, digits and -, unique on its service.

ພາຣາມິເຕີ

ຊື່ປະເພດຄ່າເລີ່ມຕົ້ນຄຳອະທິບາຍ
--serviceຕ້ອງໃສ່ຂໍ້ຄວາມContainer or function

ພາຣາມິເຕີທົ່ວໄປ

ຄຳສັ່ງນີ້ຮັບ ພາຣາມິເຕີທົ່ວໄປ ໄດ້ນຳ: --project, --region, --endpoint, --format, --quiet

ກັບຂຶ້ນເທິງ ↑

th triggers resume

Resumed a trigger.

ຮູບແບບຄຳສັ່ງ

Shell
th triggers resume NAME --service NAME

ອາກິວເມັນຕາມຕຳແໜ່ງ

ຊື່ຄຳອະທິບາຍ
NAMEຕ້ອງໃສ່The trigger’s name: lowercase letters, digits and -, unique on its service.

ພາຣາມິເຕີ

ຊື່ປະເພດຄ່າເລີ່ມຕົ້ນຄຳອະທິບາຍ
--serviceຕ້ອງໃສ່ຂໍ້ຄວາມContainer or function

ພາຣາມິເຕີທົ່ວໄປ

ຄຳສັ່ງນີ້ຮັບ ພາຣາມິເຕີທົ່ວໄປ ໄດ້ນຳ: --project, --region, --endpoint, --format, --quiet

ກັບຂຶ້ນເທິງ ↑

th triggers delete

Deletes a trigger.

ຮູບແບບຄຳສັ່ງ

Shell
th triggers delete NAME --service NAME [--quiet]

--quiet skips the prompt.

ອາກິວເມັນຕາມຕຳແໜ່ງ

ຊື່ຄຳອະທິບາຍ
NAMEຕ້ອງໃສ່The trigger’s name: lowercase letters, digits and -, unique on its service.

ພາຣາມິເຕີ

ຊື່ປະເພດຄ່າເລີ່ມຕົ້ນຄຳອະທິບາຍ
--serviceຕ້ອງໃສ່ຂໍ້ຄວາມContainer or function

ພາຣາມິເຕີທົ່ວໄປ

ຄຳສັ່ງນີ້ຮັບ ພາຣາມິເຕີທົ່ວໄປ ໄດ້ນຳ: --project, --region, --endpoint, --format, --quiet

ກັບຂຶ້ນເທິງ ↑