3

I asked a previous question getting a django command to run on a schedule. I got a solution for that question, but I still want to get my commands to run from the admin interface. The obstacle I'm hitting is that my custom management commands aren't getting recognized once I get to the admin interface.

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 forget scheduling. 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?

OrangeDog
  • 36,653
  • 12
  • 122
  • 207
Ed.
  • 4,439
  • 10
  • 60
  • 78

2 Answers2

1

I'm also using django-chronograph

and for me it works fine. I did also run once into the problem that my custom commands were not regognized by the auto-discovery feature. I think the first reason was because the custom command had an error in it. Thus it might be an idea to check whether your custom commands run without problems from the command line.

The second reason was indeed some strange path issue. I might check back with my hosting provider to provide you with a solution. Will post back to you in a few days..

Thomas Kremmel
  • 14,575
  • 26
  • 108
  • 177
  • Thanks! The command definitely works from the command line. Flawlessly. I also suspect some sort of path problem. But I checked the PYTHONPATH etc and I think everything looks ok. Frustrating. Let me know if you find anything. – Ed. Dec 26 '10 at 02:37
  • For my case it was some unix path issue. I develop on a windows machine and deploy on a unix server. On the windows machine it worked fine, but on the unix server I had similar problems. I think the chronograph source was also optimized for windows. But I will ask the guy who is administrating the server. I'm also not an unix guy. – Thomas Kremmel Dec 26 '10 at 10:45
  • yep, I plan to. Right now, I'm just testing locally on Ubuntu (so yes to unix) – Ed. Dec 26 '10 at 18:31
  • please see also: https://bitbucket.org/wnielson/django-chronograph/issue/9/setting-of-scheduled-time - there I posted some adapted code which deals with setting of the scheduled time and on line 192 it deals with the unix path problem. maybe this already resolves your issue. I use this source as it is posted there as a replacement to the original source, and it works fine for me. – Thomas Kremmel Dec 28 '10 at 13:30
0

i am the "unix-guy" mentioned above by tom tom.

as far as i remember there were some issues in the cronograph code itself, so it would be a good idea to use the code tom tom posted in the comments.

where on the filesystem is django-cronograph stored (in you app-folder, in an extra "lib-folder" or in your site-packages?

when you have it in site-packages or another folder that is in your "global pythonpath" pathing should be no issue.

the cron-process itself DOES NOT USE THE SAME pythonpath, as your django app. remember: you start the cron-process via your crontab - right? so there are 2 different process who do not "know" each other: the cron-process AND the django-process (initialized by the webserver) so i would suggest to call the following script via crontab and export pythonpath again:

#!/bin/bash

PYTHONPATH=/path/to/libs:/path/to/project_root:/path/to/other/libs/used/in/project
export PYTHONPATH

python /path/to/project/manage.py cron

so the cron-started-process has the same pythonpath-information as your project.

greez from vienna/austria

berni

bmaeser
  • 982
  • 7
  • 13
  • Awesome! Finally got it to work. I combined this with a suggestion I got from a previous question: cd /path/to/project && ./manage.py cron – Ed. Dec 30 '10 at 14:55
  • did you also used the adapted code as I posted it at bitbucket, or did it work for you with the original code? – Thomas Kremmel Dec 30 '10 at 15:20