Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hvuhsg/ants
Allow you to create you'r own custom decentralize job management system.
https://github.com/hvuhsg/ants
Last synced: 7 days ago
JSON representation
Allow you to create you'r own custom decentralize job management system.
- Host: GitHub
- URL: https://github.com/hvuhsg/ants
- Owner: hvuhsg
- License: gpl-3.0
- Created: 2021-11-06T18:52:33.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-02-15T19:45:37.000Z (over 2 years ago)
- Last Synced: 2024-10-13T22:49:02.256Z (24 days ago)
- Language: Python
- Homepage:
- Size: 74.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ants
Allow you to create you'r own custom decentralize job management system.### install
```shell script
pip install pyants
```### How it works?
The library provides you with interface to add assign and do jobs in an decentralized environment.
To create your own node just override some methods:
##### node
```python
from typing import Listfrom ants import BaseNode, Job, Message
class MyNode(BaseNode):
def add_messages(self) -> List[Message]:
return [] # List of messages to send to the other nodes (every message will be saved until it expired)def process_messages(self, messages: List[Message]):
# Process all the current nodes messages
# (every node can create message with it ip for example)
passdef add_jobs(self) -> List[Job]:
return [] # List of jobs to run (the nodes can create duplicate jobs and the lib will manage that)def assign_to_jobs(self, pending_jobs: List[Job]) -> List[Job]:
# You can choose which jobs to assign your self to
return [] # List of jobs to assign your self todef do_jobs(self, my_assigned_jobs: List[Job]):
# this list do not have to match the list you returned from the assign_to_jobs method,
# the library will manage the job distribution to the nodes.
# loop over your assigned jobs and complete them
for assigned_job in my_assigned_jobs:
# do your job
# after you complete a job, report it with job.set_result({'status': 'OK'})
pass
def completed_jobs(self, done_jobs: List[Job]):
# Here you can be updated about the jobs that has done by all the nodes
# you can store it and use it in your business logic
# For example do not create a operational check for some server if it bin checked recently
pass
```
##### communication
The communication class expose tow methods:
- pull
- broadcastThe 'pull' method should return list of state objects from other nodes
The 'broadcast' method should transfer your state to other nodesThe library implemented for you a simple p2p socket server communication for decentralized networking
```python
from ants.communications.socketserver import SocketCommunicationcommunication = SocketCommunication(host=..., port=..., pull_interval=..., bootstrap_nodes=...)
```### Example
Decentralized monitor example.
```shell script
$> git clone https://github.com/hvuhsg/ants.git
$> cd ants/examples/monitor
$> python3 -m venv venv
$> . venv/bin/activate
$> pip install -r requirements.txt
$> pip install ../../.
$> python run.py
```