-
Step 1: Install psycopg2
poetry add psycopg2OR
poetry add psycopg2-binary -
Step 2: Install rosemary:
poetry add rosemary
How to use:
- Create file
rosemary_config.pyfor initial config for connect to DB and etc.
from rosemary.rosemary import Rosemary
rosemary = Rosemary(
# Your db host
db_host='0.0.0.0',
# Your db password
db_password='postgres',
# Your db port. Optional, default = 5432
db_port=5432,
# Your db user
db_user='postgres',
# Your db name
db_name_db='postgres',
# Count of tasks which one worker can run in one time, Minimum 1
max_tasks_per_worker=30,
# Count of your workers. If one of worker will be died, rosemary recreate it.
# Minimum 1
workers=3,
)
- How to create task:
Create file with your tasks. For example
tasks.py. You can create many files for your tasks.
from rosemary_config import rosemary
import random
import asyncio
from rosemary import RosemaryInterval
from rosemary.tasks.constants import TypeTaskRosemary
... other imports...
# Example manual task
class SleepTask(rosemary.ManualTask):
# Count maximum repeat task if happened some exception
max_retry = 3
# Delay before retry when happen exception
delay_retry: RosemaryInterval = RosemaryInterval(seconds=5)
# Delay for repeatable tasks. Using when tasks recreate
delay_repeat: RosemaryInterval = RosemaryInterval(seconds=10)
# How much time waiting for one task
timeout = 30
async def run(self):
sleep = random.randint(1, 10)
await asyncio.sleep(sleep)
return f"I slept {sleep} sec"
class ExampleTask(rosemary.ManualTask):
# You can use optional params for your task:
async def run(self, data, session):
query = select(RosemaryTaskModel).where(
RosemaryTaskModel.name == self.get_name()
).order_by(RosemaryTaskModel.id)
result = await session.execute(query)
task_db: list[RosemaryTaskModel] = result.scalars().all()
result = task_db[-1].id
logger.info(f'Task ID GET: {result}')
return result
- Create file
rosemary_runner.py. You will use for run rosemary:
from rosemary_config import rosemary
from tasks import ExampleTask, SleepTask
# Register your task in runner
rosemary.register_task(SleepTask)
rosemary.register_task(ExampleTask)
if __name__ == '__main__':
# Run your rosemary
rosemary.run()
- Implement your task:
from task import SleepTask
async def main():
task_id = await SleepTask().create()
print(f'You create task {task_id}')
another_task_id = await SleepTask().create(data={123: 456, 'example': 'example123'})
print(f'You create another task {another_task_id} with params')
Requirements:
- python = "^3.11"
- pydantic = "^2"
- sqlalchemy = "^2"
- asyncpg = "^0.29.0"
- asyncio = "^3"
- logger = "^1"
- importlib = "^1"
- setuptools = "^69"
- alembic = "^1"
- greenlet = "^3"
Manual install:
- psycopg2-binary or psycopg2
Metadata
Release files for rosemary 1.8.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rosemary-1.8.0.tar.gz | 39.4 kB | Without provenance | Details for rosemary-1.8.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rosemary-1.8.0-py3-none-any.whl | Python 3 | none | any | Details for rosemary-1.8.0-py3-none-any.whl |
Total release size: 60.8 kB
Release files / rosemary-1.8.0.tar.gz
| Download URL | rosemary-1.8.0.tar.gz |
|---|---|
| Size | 39.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b0f8b6162a50da7afb39c7ddb740eb11086cc2366ec19fa2b94de83cc366c259
|
|
BLAKE2b-256 checksum How to use checksums |
1f8e707465164516d0bf2e041a8ffdf98673a3bcf6fed4bb71d835ee29726180
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.6.1 CPython/3.11.5 Darwin/23.0.0
|
Release files / rosemary-1.8.0-py3-none-any.whl
| Download URL | rosemary-1.8.0-py3-none-any.whl |
|---|---|
| Size | 21.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e0d64941b071c014432c853c6079bd51dd398a85b39daad5e645cf7ce619128f
|
|
BLAKE2b-256 checksum How to use checksums |
71c15e5abf79d2bbfcca80928bf3e1c8ccf0c97009476366ec7aa5af30b06570
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.6.1 CPython/3.11.5 Darwin/23.0.0
|
Security for rosemary 1.8.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.