Package: rdbbeat
RDBBeatrdbbeatis a SQLAlchemy-based scheduler for celery-beat that persists periodic tasks in a relational database.Table Of ContentsInstallationCelery ConfigurationUsageDeploymentFlask Service ExampleContributionSetupVersion ControlWorkflowsLicenseAcknowledgementsNOTE:We assume prior knowledge of session management in SQLAlchemy and migrations in Alembic. If you are not familiar with these concepts, please read the documentation forSQLAlchemyandAlembic.InstallationThe library is available for download from the official pypi website:pip install rdbbeatOr you can build the library for the source code hosted publicly on GitHub.Celery ConfigurationThe library makes use of the parent service's database and scope management mechanism.
You can configure SQLAlchemysession_scopewhen you configure celery, for example as:fromceleryimportCelery# this comes from parent servicefromserver.dbimportsession_scopecelery=Celery('tasks')celery.conf.update({'session_scope':session_scope})UsageCreating crontab-based periodic taskA crontab schedule has the fields:minute,hour,day_of_week,day_of_monthandmonth_of_year, so if you want the equivalent of a30 * * * *(execute every 30 minutes) crontab entry, you specify:fromrdbbeat.controllerimportschedule_taskfromrdbbeat.data_modelsimportScheduledTaskscheduled_task={"name":"task_1","task":"echo","schedule":{"minute":"30","hour":"*","day_of_week":"*","day_of_month":"*","month_of_year":"*","timezone":"UTC",},}withsession_scope()assession:task=schedule_task(session,ScheduledTask.parse_ob(scheduled_task))The crontab schedule is linked to a specific timezone using thetimezoneinput parameter.Run the migrationsrdbbeatincludes a migration script that is required to create the database tables in theschedulerschema. Run the following command to run the migrations:python-malembic-nschedulerupgradeheadDeploymentThe periodic tasks still need 'workers' to execute them. So make sure
the defaultCelerypackage is installed. (If not installed, please
follow the installation instructions here:https://github.com/celery/celery)Both the worker and beat services need to be running at the same time.Start a Celery worker service (specify your project name):$ celery -A [project-name] worker --loglevel=infoAs a separate process, start the beat service (specify the
scheduler):$ celery -A [project-name] beat -l info --scheduler rdbbeat.schedulers:DatabaseSchedulerFlask Service ExampleCheck out therdbbeat-flask-examplerepo for a simple Flask service that usesrdbbeatto schedule periodic tasks.ContributionSetupThis project is setup to useeditorconfig. Most editors work but some require a plugin likeVSCodeIt's advisable to create a virtual environment for this project to keep packages separate.NOTE:Using pyenv, you can runpyenv virtualenv 3.10.<latest> celery-sqlalchemy-schedulerAfter creating a virtual environment, install the required dependencies.justsetup-devVersion ControlThis repo follows theSemVer 2version format.Given a version numberMAJOR.MINOR.PATCH, increment the:MAJORversion when you make incompatible API changes,MINORversion when you add functionality in a backwards compatible manner, andPATCHversion when you make backwards compatible bug fixes.WorkflowsThe repository has a number of github workflows defined in the the.github/workflowsfolder.Lint & Test CodeTests the code for linting issuesTests the requirements file for any changesRuns the provided unit tests to ensure code qualityReleasePushes the library to PypiLicenseMIT licensed. See the bundled LICENSE file for more details.Acknowledgementsdjango-celery-beatcelerybeatrediscelerycelery-sqlalchemy-scheduler