refactor: уникальные имена функций-обработчиков
handle() → run_sql() (sql_runner.py, entrypoint: sql_runner.run_sql) handle() → crud() (notes_crud.py, entrypoint: notes_crud.crud) handle() → list_notes() (notes_list.py, entrypoint: notes_list.list_notes)
This commit is contained in:
parent
49035d35f0
commit
74d288c7a7
@ -15,7 +15,7 @@ import psycopg2
|
||||
import psycopg2.extras
|
||||
|
||||
|
||||
def handle(event):
|
||||
def list_notes(event):
|
||||
dsn = os.environ['PG_DSN']
|
||||
conn = psycopg2.connect(dsn)
|
||||
try:
|
||||
|
||||
@ -17,7 +17,7 @@ import psycopg2
|
||||
import psycopg2.extras
|
||||
|
||||
|
||||
def handle(event):
|
||||
def crud(event):
|
||||
dsn = os.environ['PG_DSN']
|
||||
# sub-path без ведущего слэша: "add", "update", "delete"
|
||||
action = event.get('_path', '/').strip('/')
|
||||
|
||||
@ -19,7 +19,7 @@ import os
|
||||
import psycopg2
|
||||
|
||||
|
||||
def handle(event):
|
||||
def run_sql(event):
|
||||
dsn = os.environ['PG_DSN']
|
||||
statements = event.get('statements', [])
|
||||
if not statements:
|
||||
|
||||
BIN
notes-python/dist/notes-list.zip
vendored
BIN
notes-python/dist/notes-list.zip
vendored
Binary file not shown.
BIN
notes-python/dist/notes.zip
vendored
BIN
notes-python/dist/notes.zip
vendored
Binary file not shown.
BIN
notes-python/dist/sql-runner.zip
vendored
BIN
notes-python/dist/sql-runner.zip
vendored
Binary file not shown.
@ -16,12 +16,12 @@ data "archive_file" "notes_list_zip" {
|
||||
}
|
||||
|
||||
# Read-only функция в кластере.
|
||||
# entrypoint = "notes_list.handle" → файл notes_list.py, функция handle().
|
||||
# entrypoint = "notes_list.list_notes" → файл notes_list.py, функция list_notes().
|
||||
resource "sless_function" "notes_list" {
|
||||
namespace = "default"
|
||||
name = "notes-list"
|
||||
runtime = "python3.11"
|
||||
entrypoint = "notes_list.handle"
|
||||
entrypoint = "notes_list.list_notes"
|
||||
memory_mb = 128
|
||||
timeout_sec = 30
|
||||
|
||||
|
||||
@ -18,12 +18,12 @@ data "archive_file" "notes_crud_zip" {
|
||||
}
|
||||
|
||||
# CRUD функция в кластере.
|
||||
# entrypoint = "notes_crud.handle" → файл notes_crud.py, функция handle().
|
||||
# entrypoint = "notes_crud.crud" → файл notes_crud.py, функция crud().
|
||||
resource "sless_function" "notes_crud" {
|
||||
namespace = "default"
|
||||
name = "notes"
|
||||
runtime = "python3.11"
|
||||
entrypoint = "notes_crud.handle"
|
||||
entrypoint = "notes_crud.crud"
|
||||
memory_mb = 128
|
||||
timeout_sec = 30
|
||||
|
||||
|
||||
@ -14,13 +14,13 @@ data "archive_file" "sql_runner_zip" {
|
||||
}
|
||||
|
||||
# Сама функция в кластере.
|
||||
# entrypoint = "sql_runner.handle" → файл sql_runner.py, функция handle().
|
||||
# entrypoint = "sql_runner.run_sql" → файл sql_runner.py, функция run_sql().
|
||||
# memory_mb=128 достаточно — DDL запросы не требуют памяти на вычисления.
|
||||
resource "sless_function" "sql_runner" {
|
||||
namespace = "default"
|
||||
name = "sql-runner"
|
||||
runtime = "python3.11"
|
||||
entrypoint = "sql_runner.handle"
|
||||
entrypoint = "sql_runner.run_sql"
|
||||
memory_mb = 128
|
||||
timeout_sec = 30
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user