An open API service indexing awesome lists of open source software.

https://github.com/fcrozetta/moirai

moirai engine
https://github.com/fcrozetta/moirai

Last synced: 4 months ago
JSON representation

moirai engine

Awesome Lists containing this project

README

          

# moirai-engine

[![PyPI - Version](https://img.shields.io/pypi/v/moirai-engine.svg)](https://pypi.org/project/moirai-engine)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/moirai-engine.svg)](https://pypi.org/project/moirai-engine)

-----

## Table of Contents

- [moirai-engine](#moirai-engine)
- [Table of Contents](#table-of-contents)
- [Installation](#installation)
- [Usage](#usage)
- [Basic Example](#basic-example)
- [Advanced Example](#advanced-example)
- [About](#about)
- [License](#license)

> **NOTE:** This doc is still in progress. for now it was generated by AI (sorry).

## Installation

```console
pip install moirai-engine
```

## Usage

### Basic Example

Here is a basic example of how to use the `moirai-engine` library to create and run a simple job:

```python
import time
from moirai_engine.core.engine import Engine
from moirai_engine.utils.samples import hello_world

# Create and start the engine
engine = Engine()
engine.start()

# Create a job using the hello_world sample
job = hello_world()

# Add the job to the engine
engine.add_job(job)

# Let the engine run for a while
time.sleep(5)

# Stop the engine
engine.stop()
```

### Advanced Example

Here is an advanced example that includes real-time notifications and job cancellation:

```python
import asyncio
from moirai_engine.core.engine import Engine
from moirai_engine.utils.samples import hello_world

# Create an async function
async def notification_listener(notification):
print(f"Received notification: {notification}")

async def main():
engine = Engine(max_workers=4, listener=notification_listener)
await engine.start()

# Add jobs to the engine
await engine.add_job(hello_world(), notification_listener)

# Let the engine run for a while
await asyncio.sleep(2)

await engine.stop()

if __name__ == "__main__":
asyncio.run(main())

```

## About

`moirai-engine` is the engine that powers [Ananke](https://github.com/fcrozetta/ananke), but it was planned to be used as a processing engine. This project is still in progress, and features like task registry and autodiscover are still in development.

## License

MIT License