diff --git a/hello-node/code/handler-job.js b/hello-node/code/handler-job.js index 5081ff9..23abed8 100644 --- a/hello-node/code/handler-job.js +++ b/hello-node/code/handler-job.js @@ -1,10 +1,11 @@ // 2026-03-08 -// handler-job.js — batch-функция: суммирует числа из переданного массива. +// handler-job.js — batch-функция: суммирует числа и считает среднее. // Используется с sless_job (одноразовый запуск). // event.numbers — массив чисел, например [1, 2, 3, 4, 5] exports.handle = async (event) => { const numbers = event.numbers || []; const sum = numbers.reduce((acc, n) => acc + n, 0); - return { input: numbers, sum, count: numbers.length }; + const avg = numbers.length > 0 ? sum / numbers.length : 0; + return { input: numbers, sum, avg, count: numbers.length }; }; diff --git a/hello-node/handler-http.zip b/hello-node/handler-http.zip index eb7a08c..4aa7d77 100644 Binary files a/hello-node/handler-http.zip and b/hello-node/handler-http.zip differ diff --git a/hello-node/handler-job.zip b/hello-node/handler-job.zip index a88be32..5074c2f 100644 Binary files a/hello-node/handler-job.zip and b/hello-node/handler-job.zip differ diff --git a/hello-node/job.tf b/hello-node/job.tf index d8bf31e..8c54270 100644 --- a/hello-node/job.tf +++ b/hello-node/job.tf @@ -34,9 +34,9 @@ resource "sless_job" "hello_run" { namespace = "default" name = "hello-run" function = sless_function.hello_job.name - event_json = jsonencode({ numbers = [1, 2, 3, 4, 5] }) + event_json = jsonencode({ numbers = [100, 200, 300] }) wait_timeout_sec = 600 - run_id = 7 + run_id = 9 } output "job_phase" { diff --git a/hello-node/main.tf b/hello-node/main.tf index b861a85..6ca0850 100644 --- a/hello-node/main.tf +++ b/hello-node/main.tf @@ -8,7 +8,7 @@ terraform { required_providers { sless = { source = "terra.k8c.ru/naeel/sless" - version = "~> 0.1.5" + version = "~> 0.1.6" } archive = { source = "hashicorp/archive" diff --git a/hello-node/terraform.tfstate.1773029146.backup b/hello-node/terraform.tfstate.1773029146.backup new file mode 100644 index 0000000..1681c79 --- /dev/null +++ b/hello-node/terraform.tfstate.1773029146.backup @@ -0,0 +1,209 @@ +{ + "version": 4, + "terraform_version": "1.12.2", + "serial": 68, + "lineage": "d12fc078-7aee-39d1-629d-358c3c135820", + "outputs": { + "job_completion_time": { + "value": "2026-03-08T17:10:15Z", + "type": "string" + }, + "job_message": { + "value": "completed successfully", + "type": "string" + }, + "job_phase": { + "value": "Succeeded", + "type": "string" + }, + "trigger_url": { + "value": "https://sless-api.kube5s.ru/fn/default/hello-http", + "type": "string" + } + }, + "resources": [ + { + "mode": "data", + "type": "archive_file", + "name": "handler_http", + "provider": "provider[\"registry.terraform.io/hashicorp/archive\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "exclude_symlink_directories": null, + "excludes": null, + "id": "af56405ad089f54b3382b1f8bbf648e9a4020186", + "output_base64sha256": "5k1JGBxCX5TLgrWRw8F4O3rMWu/4dprgLd9EH+maLx4=", + "output_base64sha512": "E6SsXf62mq4oPTpoiH9LXKdCy0nq4o8bANVfkYqd5JTvIGxXr/ow7DYqotFvJc1GIFMyo4etB54CKVduAEzWDw==", + "output_file_mode": null, + "output_md5": "8f2434a1fe0b8f791c4c39848c1c1db0", + "output_path": "./handler-http.zip", + "output_sha": "af56405ad089f54b3382b1f8bbf648e9a4020186", + "output_sha256": "e64d49181c425f94cb82b591c3c1783b7acc5aeff8769ae02ddf441fe99a2f1e", + "output_sha512": "13a4ac5dfeb69aae283d3a68887f4b5ca742cb49eae28f1b00d55f918a9de494ef206c57affa30ec362aa2d16f25cd46205332a387ad079e0229576e004cd60f", + "output_size": 419, + "source": [], + "source_content": null, + "source_content_filename": null, + "source_dir": null, + "source_file": "./code/handler-http.js", + "type": "zip" + }, + "sensitive_attributes": [], + "identity_schema_version": 0 + } + ] + }, + { + "mode": "data", + "type": "archive_file", + "name": "handler_job", + "provider": "provider[\"registry.terraform.io/hashicorp/archive\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "exclude_symlink_directories": null, + "excludes": null, + "id": "e9056d193119214fe75cb187ca287199eaf326c9", + "output_base64sha256": "MbwoybKGBrsT3T/MrloAK0g+lu4qPCnAo1M0vAqR83Y=", + "output_base64sha512": "CHrmv338w4YGroUNZC7zR5vlgJvmrep5jToVJlPWjzEVeMO9J+eucD9LXzg89kzDsN/lVgCfQ3TvRE5RsOxugA==", + "output_file_mode": null, + "output_md5": "4aeae366572f35f199937c40c3708120", + "output_path": "./handler-job.zip", + "output_sha": "e9056d193119214fe75cb187ca287199eaf326c9", + "output_sha256": "31bc28c9b28606bb13dd3fccae5a002b483e96ee2a3c29c0a35334bc0a91f376", + "output_sha512": "087ae6bf7dfcc38606ae850d642ef3479be5809be6adea798d3a152653d68f311578c3bd27e7ae703f4b5f383cf64cc3b0dfe556009f4374ef444e51b0ec6e80", + "output_size": 506, + "source": [], + "source_content": null, + "source_content_filename": null, + "source_dir": null, + "source_file": "./code/handler-job.js", + "type": "zip" + }, + "sensitive_attributes": [], + "identity_schema_version": 0 + } + ] + }, + { + "mode": "managed", + "type": "sless_function", + "name": "hello_http", + "provider": "provider[\"terra.k8c.ru/naeel/sless\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "build_timeout_sec": 300, + "code_hash": "c9755d3a41cd22734918ed9c6350394cb70ddc4104031bcd8edd5e5fed9a1963", + "code_path": "./handler-http.zip", + "entrypoint": "handler-http.handle", + "env_vars": null, + "image_ref": "naeel/sless-default-hello-http:072b89774248", + "memory_mb": 128, + "name": "hello-http", + "namespace": "default", + "phase": "Ready", + "runtime": "nodejs20", + "timeout_sec": 30 + }, + "sensitive_attributes": [], + "identity_schema_version": 0, + "dependencies": [ + "data.archive_file.handler_http" + ] + } + ] + }, + { + "mode": "managed", + "type": "sless_function", + "name": "hello_job", + "provider": "provider[\"terra.k8c.ru/naeel/sless\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "build_timeout_sec": 300, + "code_hash": "4155f9367b1999fb0f80460e919dac79b6af559a603cf938d70a2a322fccc7ec", + "code_path": "./handler-job.zip", + "entrypoint": "handler-job.handle", + "env_vars": null, + "image_ref": "naeel/sless-default-hello-job:67f12d5519e3", + "memory_mb": 128, + "name": "hello-job", + "namespace": "default", + "phase": "Ready", + "runtime": "nodejs20", + "timeout_sec": 30 + }, + "sensitive_attributes": [], + "identity_schema_version": 0, + "dependencies": [ + "data.archive_file.handler_job" + ] + } + ] + }, + { + "mode": "managed", + "type": "sless_job", + "name": "hello_run", + "provider": "provider[\"terra.k8c.ru/naeel/sless\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "completion_time": "2026-03-08T17:10:15Z", + "event_json": "{\"numbers\":[10,20,30,40,50]}", + "function": "hello-job", + "message": "completed successfully", + "name": "hello-run", + "namespace": "default", + "phase": "Succeeded", + "run_id": 8, + "start_time": "2026-03-08T17:10:05Z", + "wait_timeout_sec": 600 + }, + "sensitive_attributes": [], + "identity_schema_version": 0, + "dependencies": [ + "data.archive_file.handler_job", + "sless_function.hello_job" + ] + } + ] + }, + { + "mode": "managed", + "type": "sless_trigger", + "name": "hello_http", + "provider": "provider[\"terra.k8c.ru/naeel/sless\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "active": true, + "enabled": true, + "function": "hello-http", + "name": "hello-http-trigger", + "namespace": "default", + "schedule": null, + "type": "http", + "url": "https://sless-api.kube5s.ru/fn/default/hello-http" + }, + "sensitive_attributes": [], + "identity_schema_version": 0, + "dependencies": [ + "data.archive_file.handler_http", + "sless_function.hello_http" + ] + } + ] + } + ], + "check_results": null +}