Crates.io | py_mcai_worker_sdk |
lib.rs | py_mcai_worker_sdk |
version | 2.0.0-rc2 |
source | src |
created_at | 2020-10-29 15:07:16.076452 |
updated_at | 2022-09-30 13:57:06.251368 |
description | AMQP Worker to listen and provide trait to process message |
homepage | https://gitlab.com/media-cloud-ai/sdks/py_mcai_worker_sdk |
repository | https://gitlab.com/media-cloud-ai/sdks/py_mcai_worker_sdk |
max_upload_size | |
id | 306664 |
size | 159,445 |
Based on mcai_worker_sdk.
To build the rust application
cargo build
To run the unit tests, you must build the provided worker example (see the Build section above).
cargo test
This worker uses the PyO3 crate to load a Python file, and to execute it.
To implement a worker, a pyproject.toml
file must be created with metadata describing the worker.
It must at least contain both project
and build-system
sections.
Example: (minimal configuration)
[project]
name = "my_python_worker"
version = "1.2.3"
description = "My Python worker"
license = { text = "MIT" }
[build-system]
requires = []
The Python worker parameters must be into a Python class as static attributes. Each parameter type must be explicitly set.
Example:
import typing
class MyWorkerParameters:
a_parameter: int
another_parameter: typing.Optional[str] = None
The Python worker itself must be defined as a Python class implementing some methods:
get_parameters_type() -> typing.Type
(static):
init()
(static):
process(handle_callback, parameters, job_id) -> dict
(static) with parameters
instance of the worker parameter
class:
If the media
feature is enabled, the following function must be implemented:
init_process(stream_handler, format_context, parameters) -> list
(static) with parameters
instance of the worker
parameter class:
GenericStreamDescriptor
sprocess_frames(job_id, stream_index, frames) -> dict
(static):
process_ebu_ttml_live(job_id, stream_index, ttml_contents) -> dict
(static):
ending_process()
(static):
NB: the process(handle_callback, parameters, job_id) -> dict
function is not called when the media
feature is
enabled.
For more details, see the provided worker.py and media_worker.py examples.
Set the PYTHON_WORKER_FILENAME
environment variable to specify the path of your Python worker. Otherwise,
the worker.py
file will be loaded by default.
RUST_LOG=debug \
SOURCE_ORDERS="examples/message.json" \
PYTHON_WORKER_FILENAME="worker.py" \
SOURCE_PATH="README.md" \
DESTINATION_PATH="README.md.out" \
cargo run
First set the media filename:
export SOURCE_PATH="/folder/filename.ext"
Then run the SDK with these parameters:
RUST_LOG=debug \
SOURCE_ORDERS="examples/message.json" \
PYTHON_WORKER_FILENAME="media_worker.py" \
DESTINATION_PATH="results.json" \
cargo run --features media