examples/hello-node: two different functions (http greeting, job sum)

This commit is contained in:
“Naeel”
2026-03-08 09:22:38 +04:00
parent 00cd3d181b
commit 4f0b8fb486
6 changed files with 43 additions and 26 deletions
+12 -5
View File
@@ -1,5 +1,6 @@
# 2026-03-08
# job.tf — вариант с одноразовым запуском: terraform apply выполняет функцию и ждёт результата.
# job.tf — одноразовая функция: суммирует числа из переданного массива.
# Код: code/handler-job.js
#
# Использование:
# terraform apply
@@ -8,16 +9,22 @@
#
# Повторный запуск — изменить event_json и снова terraform apply.
data "archive_file" "handler_job" {
type = "zip"
source_file = "${path.module}/code/handler-job.js"
output_path = "${path.module}/handler-job.zip"
}
resource "sless_function" "hello_job" {
namespace = "default"
name = "hello-job"
runtime = "nodejs20"
entrypoint = "handler.handle"
entrypoint = "handler-job.handle"
memory_mb = 128
timeout_sec = 30
code_path = data.archive_file.handler.output_path
code_hash = data.archive_file.handler.output_md5
code_path = data.archive_file.handler_job.output_path
code_hash = data.archive_file.handler_job.output_md5
}
# Одноразовый запуск. Все поля immutable — изменение любого пересоздаёт джоб.
@@ -25,7 +32,7 @@ resource "sless_job" "hello_run" {
namespace = "default"
name = "hello-run"
function = sless_function.hello_job.name
event_json = jsonencode({ name = "Naeel" })
event_json = jsonencode({ numbers = [1, 2, 3, 4, 5] })
wait_timeout_sec = 120
}