I am having difficulty getting my custom command to run on schedule. I'm
using django-chronograph, but I can't seem to get it to run like it can
(successfully) from the command line. Before I go into the background of
this problem, I will state my question: H*ow might I run a custom management
command from the django admin graphical interface to prove that it can
indeed be done? Or rather, how can I make sure that custom management
commands available from said interface?*
I'm just developing an app locally using django installed on Ubunutu.
I have a custom command that I use to clear out log entries that are greater
than 30 days old. In order to test it repeatedly, I altered it so that it
only deletes one somewhat arbitrary entry:
from datetime import datetime, timedelta
from hitcount.models import Hit
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
args = '<days>'
help = 'Clear out all Hits that occured over "days" days ago'
def handle(self, *args, **options):
list = Hit.objects.filter(created__lt =
datetime.now()-timedelta(days=2) )
list[0].delete()
self.stdout.write('Hit deleted - %s' % list[0])
This command (del_hit.py) is located in the following structure:
/project_dir
/app
/management
__init__.py
/commands
__init__.py
del_hit.py
As I stated, I can successfully run this command from my project_dir
python manage.py del_hit
I tried installing django-chronograph. It seems very useful. It recognized
my command and allowed me to select it from a drop down list. However, when
it tries to execute the command, it gives me the following error in the log:
The job failed to run. The exception was :
Unknown command: u'del_hit'
Traceback (most recent call last):
File "/home/vadmin/development/python/my_proj/chronograph/models.py", line
213, in handle_run
call_command(self.command, *args, **options)
File "/usr/lib/python2.6/dist-packages/django/core/management/__init__.py",
line 155, in call_command
raise CommandError("Unknown command: %r" % name)
CommandError: Unknown command: u'del_hit'
I traced this back to the __init__.py file of the django/core/management
utility. There seems to be some strange behavior going on. When the server
first comes up, a dictionary variable _commands is populated with the core
commands (from django/core/management/commands). Custom management commands
from all of the installed apps are also pushed into the _commands variable
for an overall dictionary of all management commands.
Somehow, though between when the server starts and when django chronograph
goes to run the job from the admin interface, the _commands variable loses
the custom commands; the only commands in the dictionary are the core
commands. I'm not sure why this is. Could it be a path issue? Am I
missing some setting? Is it a django-chronograph specific problem? *So how
might I run a custom management command from the django admin graphical
interface to prove that it can indeed be done? Or rather, how can I make
sure that custom management commands available from said interface?*
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.