Metadata-Version: 2.4
Name: haps-runtime-executor
Version: 0.4.1
Summary: Execution daemon for HAPS runtimes: pulls pending jobs and runs them
Author: Logica Team, Universite de Rennes / IRISA
Author-email: Benjamin De Zordo <benjamin.de-zordo@irisa.fr>
License-Expression: MIT
Project-URL: Homepage, https://www.irisa.fr/equipes/logica
Keywords: haps,hpc,daemon,job-runner,job-execution,ephemeral-buffers,microservices,distributed-computing
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: System Administrators
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: System :: Clustering
Classifier: Topic :: System :: Distributed Computing
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: haps-runtime==0.4.*
Requires-Dist: ebcommon==2.0.0a0
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: ruff>=0.6; extra == "dev"
Dynamic: license-file

# haps-runtime-executor

Execution daemon for HAPS runtimes: it watches a runtime, picks up the pending
jobs and runs each one in its own thread. You only write what a job does.

Built on [`haps-runtime`](https://pypi.org/project/haps-runtime/).

## Install

```bash
pip install haps-runtime-executor
```

Requires Python 3.11 or newer.

## Quick start

```python
from haps_runtime import HapsClient
from haps_runtime_executor import RuntimeJob, RuntimeJobError, RuntimeService


class EchoJob(RuntimeJob):
    def execute(self) -> None:
        if not self.job.arguments:
            raise RuntimeJobError("no argument given")  # the job ends FAILED

    def voutput(self, index: int, name: str) -> str:
        return self.job.arguments[0]


client = HapsClient(
    ebservice_url="https://ebservice.example.org/api/v1",
    ebuffer_url="https://ebuffer.example.org/api/v1",
    username="maintainer",
    password="secret",
)
runtime = client.runtimes.find(accepted_mime_type="application/x-echo")[0]

service = RuntimeService(runtime, EchoJob, polltime=5)
service.start()
service.join()
```

## Hooks

Override what your job needs, all optional:

| Hook | Called |
|---|---|
| `vinput(index, name, value)` | for each scalar argument |
| `ebinput(index, name, buffer_uuid)` | for each input buffer |
| `execute()` | once, to do the work |
| `voutput(index, name)` | for each result, returns its value |
| `eboutput(index, name, buffer_uuid)` | for each output buffer |
| `on_stop()` | when the job is stopped or cancelled |
| `cleanup()` | always, at the end |

## Errors

Raise one of these to say how far a failure goes:

| Exception | Stops |
|---|---|
| `RuntimeJobError` | this job |
| `RuntimeRunnerError` | this application's runner |
| `RuntimeServiceError` | the whole daemon |

## License

MIT
