เกี่ยวกับ
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 อัน
คู่มือการใช้งาน
สั่งงานทุกคืน
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
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 create | Creates a trigger that POSTs to the service without a visitor. |
th triggers list | Lists the triggers of a Container or function. |
th triggers update | Changes a trigger; flags left out keep their value. |
th triggers run | Fires a cron trigger once now, outside its schedule. |
th triggers pause | Paused a trigger. |
th triggers resume | Resumed a trigger. |
th triggers delete | Deletes a trigger. |
th triggers create
Creates a trigger that POSTs to the service without a visitor.
ไวยากรณ์
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)ตัวอย่าง
th triggers create nightly --service api --schedule "0 3 * * *" --path /tasks/nightlyth 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/Bangkok | Time zone of the schedule |
--body | ข้อความ | JSON naming the run | Request body of a cron run |
--queue | ข้อความ | Queue whose messages call the service | |
--concurrency | ตัวเลข | 1 | Queue 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.
ไวยากรณ์
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.
ไวยากรณ์
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/Bangkok | Time zone of the schedule |
--body | ข้อความ | JSON naming the run | Request body of a cron run |
--queue | ข้อความ | Queue whose messages call the service | |
--concurrency | ตัวเลข | 1 | Queue 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.
ไวยากรณ์
th triggers run NAME --service NAMESee the result with th triggers list.
อาร์กิวเมนต์ตามตำแหน่ง
| ชื่อ | คำอธิบาย |
|---|---|
NAMEจำเป็น | ชื่อ Trigger: ตัวพิมพ์เล็ก ตัวเลข และ - ไม่ซ้ำกันในบริการเดียวกัน |
พารามิเตอร์
| ชื่อ | ชนิด | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
--serviceจำเป็น | ข้อความ | Container or function |
พารามิเตอร์ส่วนกลาง
คำสั่งนี้รับพารามิเตอร์ส่วนกลางด้วย: --project, --region, --endpoint, --format, --quiet
th triggers pause
Paused a trigger.
ไวยากรณ์
th triggers pause NAME --service NAMEอาร์กิวเมนต์ตามตำแหน่ง
| ชื่อ | คำอธิบาย |
|---|---|
NAMEจำเป็น | ชื่อ Trigger: ตัวพิมพ์เล็ก ตัวเลข และ - ไม่ซ้ำกันในบริการเดียวกัน |
พารามิเตอร์
| ชื่อ | ชนิด | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
--serviceจำเป็น | ข้อความ | Container or function |
พารามิเตอร์ส่วนกลาง
คำสั่งนี้รับพารามิเตอร์ส่วนกลางด้วย: --project, --region, --endpoint, --format, --quiet
th triggers resume
Resumed a trigger.
ไวยากรณ์
th triggers resume NAME --service NAMEอาร์กิวเมนต์ตามตำแหน่ง
| ชื่อ | คำอธิบาย |
|---|---|
NAMEจำเป็น | ชื่อ Trigger: ตัวพิมพ์เล็ก ตัวเลข และ - ไม่ซ้ำกันในบริการเดียวกัน |
พารามิเตอร์
| ชื่อ | ชนิด | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
--serviceจำเป็น | ข้อความ | Container or function |
พารามิเตอร์ส่วนกลาง
คำสั่งนี้รับพารามิเตอร์ส่วนกลางด้วย: --project, --region, --endpoint, --format, --quiet
th triggers delete
Deletes a trigger.
ไวยากรณ์
th triggers delete NAME --service NAME [--quiet]--quiet skips the prompt.
อาร์กิวเมนต์ตามตำแหน่ง
| ชื่อ | คำอธิบาย |
|---|---|
NAMEจำเป็น | ชื่อ Trigger: ตัวพิมพ์เล็ก ตัวเลข และ - ไม่ซ้ำกันในบริการเดียวกัน |
พารามิเตอร์
| ชื่อ | ชนิด | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
--serviceจำเป็น | ข้อความ | Container or function |
พารามิเตอร์ส่วนกลาง
คำสั่งนี้รับพารามิเตอร์ส่วนกลางด้วย: --project, --region, --endpoint, --format, --quiet