th triggers

เรียก Container หรือ Function ตามเวลา (Cron) หรือทุกข้อความที่เข้า Queue

เกี่ยวกับ

Trigger ส่ง HTTP POST ไปที่ Path ของ Container หรือ Function โดยไม่ต้องมีผู้เข้าชม ใช้ได้กับบริการที่เป็น Internal หรือต้องใช้ Token และปลุกบริการที่หยุดอยู่ให้ทำงาน

  • Cron (--schedule): 5 ช่อง นาที ชั่วโมง วัน เดือน วันในสัปดาห์ หรือ @hourly, @daily, @weekly, @monthly ตาม --time-zone (ค่าเริ่มต้น Asia/Bangkok) Body คือ --body หรือ JSON ที่บอกรอบที่ทำงาน
  • Queue (--queue): ทุกข้อความใน Queue ของ Project เดียวกัน ครั้งละ --concurrency ข้อความ (1–10) ส่งเป็น JSON {"trigger","queue","message":{"id","body","attributes","sentAt","receives"}} ตอบ 2xx = ลบข้อความ ตอบอย่างอื่นจะส่งใหม่หลัง 10 วินาที และรอนานขึ้นทีละเท่าจนถึง 10 นาที เมื่อเกิน Max receives ของ Queue จะย้ายไป Dead-letter queue

Request จาก Trigger มี header X-TH-Trigger, X-TH-Trigger-Id และ X-TH-Trigger-Kind (Queue มี X-TH-Trigger-Queue, X-TH-Trigger-Message-Id และ X-TH-Trigger-Receives ด้วย) ระบบลบ header ชุดนี้ออกจาก request ของผู้เข้าชม แอปจึงเชื่อถือได้ บริการหนึ่งมี Trigger ได้ไม่เกิน 20 อัน

คู่มือการใช้งาน

สั่งงานทุกคืน

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

บน Git Bash ให้ขึ้นต้น Path ด้วย // หรือตั้ง MSYS_NO_PATHCONV=1 เพราะ Git Bash แปลงอาร์กิวเมนต์ที่ขึ้นต้นด้วย / เป็น Path ของ Windows

ประมวลผล 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จำเป็นชื่อ Trigger: ตัวพิมพ์เล็ก ตัวเลข และ - ไม่ซ้ำกันในบริการเดียวกัน
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จำเป็นชื่อ Trigger: ตัวพิมพ์เล็ก ตัวเลข และ - ไม่ซ้ำกันในบริการเดียวกัน

พารามิเตอร์

ชื่อชนิดค่าเริ่มต้นคำอธิบาย
--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จำเป็นชื่อ Trigger: ตัวพิมพ์เล็ก ตัวเลข และ - ไม่ซ้ำกันในบริการเดียวกัน

พารามิเตอร์

ชื่อชนิดค่าเริ่มต้นคำอธิบาย
--serviceจำเป็นข้อความContainer or function

พารามิเตอร์ส่วนกลาง

คำสั่งนี้รับพารามิเตอร์ส่วนกลางด้วย: --project, --region, --endpoint, --format, --quiet

กลับขึ้นด้านบน ↑

th triggers pause

Paused a trigger.

ไวยากรณ์

Shell
th triggers pause NAME --service NAME

อาร์กิวเมนต์ตามตำแหน่ง

ชื่อคำอธิบาย
NAMEจำเป็นชื่อ Trigger: ตัวพิมพ์เล็ก ตัวเลข และ - ไม่ซ้ำกันในบริการเดียวกัน

พารามิเตอร์

ชื่อชนิดค่าเริ่มต้นคำอธิบาย
--serviceจำเป็นข้อความContainer or function

พารามิเตอร์ส่วนกลาง

คำสั่งนี้รับพารามิเตอร์ส่วนกลางด้วย: --project, --region, --endpoint, --format, --quiet

กลับขึ้นด้านบน ↑

th triggers resume

Resumed a trigger.

ไวยากรณ์

Shell
th triggers resume NAME --service NAME

อาร์กิวเมนต์ตามตำแหน่ง

ชื่อคำอธิบาย
NAMEจำเป็นชื่อ Trigger: ตัวพิมพ์เล็ก ตัวเลข และ - ไม่ซ้ำกันในบริการเดียวกัน

พารามิเตอร์

ชื่อชนิดค่าเริ่มต้นคำอธิบาย
--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จำเป็นชื่อ Trigger: ตัวพิมพ์เล็ก ตัวเลข และ - ไม่ซ้ำกันในบริการเดียวกัน

พารามิเตอร์

ชื่อชนิดค่าเริ่มต้นคำอธิบาย
--serviceจำเป็นข้อความContainer or function

พารามิเตอร์ส่วนกลาง

คำสั่งนี้รับพารามิเตอร์ส่วนกลางด้วย: --project, --region, --endpoint, --format, --quiet

กลับขึ้นด้านบน ↑