1

I have to implement task on schedule , for that i am using django_cron. In setting :

INSTALLED_APPS = [
    'mailsnake',
    'corsheaders',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'Avaana_web',
    'rest_framework',
    'rest_framework.authtoken',
    'django_cron',

]

and cron.py

    from django_cron import CronJobBase, Schedule,cronScheduler
    import datetime,os
    class MyCronJob(CronJobBase):
        RUN_EVERY_MINS = .3
        RETRY_AFTER_FAILURE_MINS = 5
        ALLOW_PARALLEL_RUNS = True
        schedule = Schedule(run_every_mins=RUN_EVERY_MINS,      
  retry_after_failure_mins=RETRY_AFTER_FAILURE_MINS)
        code = 'my_app.my_cron_job'
        def do(self):
            print("hello")

but when i run

$ python manage.py runcrons
 hello

Only once output shows and ends.

How i can get output after every 30 seconds.

Alasdair
  • 298,606
  • 55
  • 578
  • 516
Manoj Datt
  • 358
  • 1
  • 3
  • 10
  • i have also install django_cron. via $ pip install django_cron – Manoj Datt Nov 09 '16 at 08:02
  • try running with `python -u manage.py runcrons` – Burhan Khalid Nov 09 '16 at 08:30
  • read #6 from this link http://django-cron.readthedocs.io/en/latest/installation.html – Anoop Nov 09 '16 at 08:43
  • how to use `django_cron` for sending email after every 30 min. on view – Manoj Datt Nov 10 '16 at 06:10
  • My cron.py contains : `from django_cron import CronJobBase, Schedule, get_class from django.core.mail import EmailMessage class my_scheduled_job(CronJobBase): RUN_EVERY_MINS = 30 schedule = Schedule(run_every_mins=RUN_EVERY_MINS) print("schedule") print(schedule) code = 'Sana_web.my_cron_job' def do(self): email = EmailMessage('title', 'body', to=[email]) email.send() ` – Manoj Datt Nov 10 '16 at 06:12

1 Answers1

1

a couple of things:

a. looks like your cron job isn't configured properly. according to doc, you need to create a CRON_CLASSES list in your settings path points to fully-qualified package name of your cron class, like this:

CRON_CLASSES = [
    "my_app.cron.MyCronJob",
    # ...
]

b. also, the point of running it via python manage doesn't mean it'll continue to run multiple times. you probably still need to run the 'python manage.py runcrons' from a cron job. your schedule will merely decide whether it needs to run when you call manage.py runcrons. see more much detail here: http://django-cron.readthedocs.io/en/latest/installation.html

matias elgart
  • 1,123
  • 12
  • 18