Implement a startup script which runs once on microservice start.
This commit is contained in:
@@ -3,6 +3,15 @@ from slingshot_microservice import Microservice
|
||||
from typing import Generator
|
||||
from sqlalchemy.engine.base import Connection
|
||||
|
||||
|
||||
def startup(
|
||||
read_file: ReadFileFn,
|
||||
write_file: WriteFileFn,
|
||||
_connection: Connection,
|
||||
) -> Generator[tuple[int, bool | int | str], None, None]:
|
||||
if False:
|
||||
yield (0, True)
|
||||
|
||||
def process(
|
||||
request: int,
|
||||
read_file: ReadFileFn,
|
||||
@@ -16,5 +25,5 @@ def process(
|
||||
yield (request, True)
|
||||
|
||||
|
||||
microservice = Microservice("simple-py-microservice", "sys-map.slingshot.cv", process)
|
||||
microservice = Microservice("simple-py-microservice", "sys-map.slingshot.cv", startup, process)
|
||||
microservice.start()
|
||||
|
||||
@@ -18,8 +18,21 @@ fn process(
|
||||
Ok(vec![(request, "case_a".to_string())])
|
||||
}
|
||||
|
||||
fn startup(
|
||||
_read_file: &ReadFileFn,
|
||||
_write_file: &WriteFileFn,
|
||||
_connection: &mut PgConnection,
|
||||
) -> Result<Vec<(u64, String)>, AnyError> {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
let microservice = Microservice::new("simple-microservice", "sys-map.slingshot.cv", process);
|
||||
let microservice = Microservice::new(
|
||||
"simple-microservice",
|
||||
"sys-map.slingshot.cv",
|
||||
startup,
|
||||
process,
|
||||
);
|
||||
|
||||
microservice.start()?;
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user