Skip to main content

No project description provided

Project description

  1. Step 1: Install psycopg2

    poetry add psycopg2=2.9.9

    OR

    poetry add psycopg2-binary=2.9.9

  2. Step 2: Install rosemary:

    poetry add rosemary

How to use:

  1. Create file rosemary_config.py for 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,  
)
  1. 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 before start task
    delay: 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
  1. 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()
  1. 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.5.2"
  • sqlalchemy = "^2.0.23"
  • asyncpg = "^0.29.0"
  • asyncio = "^3.4.3"
  • logger = "^1.4"
  • importlib = "^1.0.4"
  • setuptools = "^69.0.2"
  • alembic = "^1.13.0"

Manual install:

  • psycopg2-binary = "^2.9.9" or psycopg2 = "^2.9.9"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rosemary-1.7.12.tar.gz (36.3 kB view details)

Uploaded Source

Built Distribution

rosemary-1.7.12-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file rosemary-1.7.12.tar.gz.

File metadata

  • Download URL: rosemary-1.7.12.tar.gz
  • Upload date:
  • Size: 36.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.5 Darwin/23.0.0

File hashes

Hashes for rosemary-1.7.12.tar.gz
Algorithm Hash digest
SHA256 1a64c9ba6433651ee5d035489bf7cbb64d1e11b3035c9bc52871e4db3e0c22a2
MD5 b5cd0e4331cc8a4aa15e1064818e1d85
BLAKE2b-256 d4dc0d0e6283e32b32aa698f811c3e792415d59fd7d37f1db95e29661584e8a7

See more details on using hashes here.

File details

Details for the file rosemary-1.7.12-py3-none-any.whl.

File metadata

  • Download URL: rosemary-1.7.12-py3-none-any.whl
  • Upload date:
  • Size: 20.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.5 Darwin/23.0.0

File hashes

Hashes for rosemary-1.7.12-py3-none-any.whl
Algorithm Hash digest
SHA256 32d16842183feb35b7dd1b31228f6ec2384d79f6f059f727094e6ed6ffb03df4
MD5 5f44b260c8cec71bc892c834e97c3039
BLAKE2b-256 b218cb634e157835b3649e0bd3e8aab3b1e98a8fd1304c9592939b3b92ee4825

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page