Sterilistic / django-cron

Automatically exported from code.google.com/p/django-cron
MIT License
0 stars 0 forks source link

autodiscover blocks syncdb #17

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a new project and add django_cron.autodiscover() to your urls.py
2. Run manage syncdb
3. You get an error saying that the cron table doesn't exist

What is the expected output? What do you see instead?
Personally I would expect autodiscover to fail silently if the tables don't
exist yet.

Original issue reported on code.google.com by kylemacfarlane@gmail.com on 17 Jul 2009 at 10:23

GoogleCodeExporter commented 8 years ago
Is this still a problem? I think I may have fixed it

Original comment by Jim.mixt...@gmail.com on 28 Oct 2009 at 2:29

GoogleCodeExporter commented 8 years ago
it was still a problem 
autodiscover launch cronScheduler.execute()
so you can have in it database access in it before it creation :
so i changed : 
            status, created = Cron.objects.get_or_create(pk=1)

            # This is important for 2 reasons:
            #     1. It keeps us for running more than one instance of the
            #        same job at a time
            #     2. It reduces the number of polling threads because they
            #        get killed off if they happen to check while another
            #        one is already executing a job (only occurs with
            #        multi-threaded servers)
            if status.executing:
                return

to : 
        try:
            status, created = Cron.objects.get_or_create(pk=1)

            # This is important for 2 reasons:
            #     1. It keeps us for running more than one instance of the
            #        same job at a time
            #     2. It reduces the number of polling threads because they
            #        get killed off if they happen to check while another
            #        one is already executing a job (only occurs with
            #        multi-threaded servers)
            if status.executing:
                return
        except:
            # stop processing because we couldn't read the database
            return

Original comment by neoke...@gmail.com on 2 Nov 2011 at 3:02