feat: operator v0.1.16 — job stdout -> status.Message (feature B)
- FunctionJobReconciler: added KubeClient field (kubernetes.Interface) - getJobPodOutput(): reads pod logs via typed client after job succeeds - main.go: inject kubernetes.NewForConfigOrDie into FunctionJobReconciler - rbac.yaml: add pods/pods/log get/list/watch permissions - examples/simple-python/: job->function chain demo (Python) - examples/simple-node/: job->function chain demo (Node.js) sless_job.X.message now contains the return value of the function
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
# Создано: 2026-03-09
|
||||
# time_display.py — HTTP-функция (постоянный Deployment + Trigger).
|
||||
# Читает env JOB_TIME, которую terraform передаёт из sless_job.run_getter.message.
|
||||
# Демонстрирует цепочку: Job вычисляет данные → Function использует их через env.
|
||||
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def show_time(event):
|
||||
# JOB_TIME устанавливается terraform из статуса джоба (JSON строка)
|
||||
job_time_raw = os.environ.get("JOB_TIME", "{}")
|
||||
try:
|
||||
job_time = json.loads(job_time_raw).get("time", job_time_raw)
|
||||
except (json.JSONDecodeError, AttributeError):
|
||||
job_time = job_time_raw
|
||||
return {
|
||||
"message": f"Сервис запустился в: {job_time}",
|
||||
"path": event.get("_path", "/"),
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
# Создано: 2026-03-09
|
||||
# time_getter.py — функция запускается как Job (одноразово).
|
||||
# Возвращает JSON со временем запуска. Оператор v0.1.16 захватывает stdout
|
||||
# и записывает его в sless_job.run_getter.message — оттуда terraform передаёт
|
||||
# значение в sless_function.display через env_var JOB_TIME.
|
||||
|
||||
import json
|
||||
from datetime import datetime, timezone
|
||||
|
||||
|
||||
def get_time(event):
|
||||
# Возвращаем время в ISO 8601 UTC — без зависимостей, только stdlib
|
||||
return {"time": datetime.now(timezone.utc).isoformat()}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Для локального тестирования без оператора
|
||||
print(json.dumps(get_time({})))
|
||||
Reference in New Issue
Block a user