Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI mara_cron.schedule-job #3

Merged
merged 3 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ This package contains the following cli commands:
| -------------- | --------------
| `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.schedule-job --job-id "my_job_id"` | Schedules a job to run in less than 1 minute.
| `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
Expand Down
22 changes: 19 additions & 3 deletions mara_cron/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import click
from mara_cron import config

from . import crontab
from . import crontab, job


@click.command()
Expand All @@ -17,7 +17,7 @@ def disable(job_id: str, module_name: str):
job = crontab.get_job(cron, job_id=job_id, module_name=module_name)

if not job:
print('Could not find cronjob')
print(f'Could not find cronjob "{job_id}"', file=sys.stderr)
sys.exit(1)

job.enable(False)
Expand All @@ -40,7 +40,7 @@ def enable(job_id: str, module_name: str):
job = crontab.get_job(cron, job_id=job_id, module_name=module_name)

if not job:
print('Could not find cronjob')
print(f'Could not find cronjob "{job_id}"', file=sys.stderr)
sys.exit(1)

job.enable(True)
Expand All @@ -49,6 +49,22 @@ def enable(job_id: str, module_name: str):
sys.exit(0)


@click.command()
@click.option('--job-id', required=True,
help='The id of of the cron job.')
def schedule_job(job_id: str):
""" Schedules a job to run. """
cronjob = job.find_job(job_id)
if not cronjob:
print(f'Could not find job with id "{job_id}"', file=sys.stderr)
sys.exit(1)

crontab.append_single_execution_job(cronjob)

print(f'Job {job_id} is scheduled to run in less than 1 minute')
sys.exit(0)


@click.command()
@click.option('--with-changes', default=False, is_flag=True,
help='Lists the current crontab including the not written changes.')
Expand Down
4 changes: 2 additions & 2 deletions mara_cron/ui/schedule_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def do_schedule_run(job_id: str):
print(f'schedule {job_id}')

return response.Response(
title=f'Task scheduled',
title=f'Job scheduled',
html=bootstrap.card(
body=_.div[
_.p[
"""The task is scheduled to run in less then 1 minute."""
"""The job is scheduled to run in less then 1 minute."""
],
bootstrap.button(url='javascript:history.back()',
label='Go to last page', icon='play',
Expand Down