Lets you manage cron jobs via mara
Project description
Mara Cron
Mini package for managing cron jobs via mara.
Installation
To use the library directly:
pip install mara-cron
Config of cron jobs
To configure cron jobs in mara you just need to add a new function MARA_CRON_JOBS
in your module or app in the __init__.py
file.
Here is a sample which has two jobs:
- the job
cleanup_data_folder
clears all data from the local folder/data/
. This job is by default disabled. - the job
nightly
runs the root pipeline at 01:00 o'clock each day
Note: The MaraJob job requires that you define the PATH
environment variable in your crontab. Cron by default uses just /usr/bin:/bin
which is not enough. I recommend using the distribution default e.g. /usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
.
def MARA_CRON_JOBS():
from mara_cron.job import CronJob, MaraJob
return [
CronJob(id='cleanup_data_folder',
description='Clean up the data folder',
time_pattern='0 0 * * *',
command='rm -rf /data/*',
enabled=False),
MaraJob(id='nightly',
description="Nightly run of the BI system",
time_pattern='0 1 * * *',
command='mara_pipelines.ui.run'),
]
Local config
Sample local config to activate crontab management in your mara app:
from mara_app.monkey_patch import patch
import mara_cron.config
# Activates mara_cron jobs. If not set all jobs are
# by default disabled and can only be activated via
# executing:
# flask mara_cron.enable --job-id "my_job_id"
patch(mara_cron.config.enabled)(lambda: True)
# Optional parameter to specify a mara instance name
# This is necessary to separate multiple environments running
# on the same user
patch(mara_cron.config.instance_name)(lambda: 'prod')
CLI
This package contains the following cli commands:
Command | Description |
---|---|
mara_cron.enable --job-id "my_job_id" [--module "module_name"] |
Enables a specific job regardless of the configuration. |
mara_cron.disable --job-id "my_job_id" [--module "module_name"] |
Disables a specific job. |
mara_cron.list-crontab |
Lists the current cron tab settings |
mara_cron.list-crontab --with-changes |
Lists the current cron tab including the changes not yet written |
mara_cron.write-crontab |
Writes all not published changes to the crontab |
mara_cron.clear-crontab |
Removes all mara jobs from the crontab. Note This applies to all instances !!! |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for mara_cron-0.9.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 469398439e2a8d7bcc0375c3fdde6d0b5755edd767e9224d91c3dd368c3c5872 |
|
MD5 | c688e57e9be3adab136754230c7e00e0 |
|
BLAKE2b-256 | 3e4baf8ef053b5d07d0ef69de4a11e76558ce961bccc90e434db3ca2ec0e672f |