kraiz / django-crontab

dead simple crontab powered job scheduling for django.
Other
842 stars 112 forks source link

How do I run a job without adding it to cron #125

Open vedmant opened 3 years ago

vedmant commented 3 years ago

Environment & Versions

Settings

Details

The problem here is that I develop in docker and when developing a cron job I need to test it before even adding to cron. But looks like I can't run command without running add command?

Is there a way to run it without hash, maybe passing a path like app.cron.my_job.job? Editing crontab file in the development environment doesn't make sense (expecially with docker as it will require rebuilding whole container), also I don't need to actually run scripts on schedule in development environment, only to test them manually.

fengyuexingzi commented 1 year ago

Here's how I did it

import hashlib import json import os import sys

import django from django_crontab.crontab import Crontab

BASE_DIC = os.path.dirname(os.path.dirname(os.path.abspath(file))) if BASE_DIC not in sys.path: sys.path.insert(0, BASE_DIC)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myblog.settings")

django.setup()

jobs = django.conf.settings.CRONJOBS for job in jobs: h = hashlib.md5(json.JSONEncoder(sort_keys=True).encode( job).encode(encoding='UTF-8')).hexdigest() Crontab().run_job(h)

amzar96 commented 7 months ago

question; if the script in app.cron.weekly_stats.job got changed, do I need to add again?