Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking jobs in Django site administration #50

Closed
inspiralpatterns opened this issue Apr 11, 2017 · 6 comments
Closed

Tracking jobs in Django site administration #50

inspiralpatterns opened this issue Apr 11, 2017 · 6 comments

Comments

@inspiralpatterns
Copy link

Hi @kraiz

I scheduled a job using crontab and I would like to keep track of it in the Django site administration. I used to have a scheduled job using cron and I can see each performed task as I run

python manage.py migrate django_cron

If I try to do the same with django_crontab, I get: CommandError: App 'django_crontab' does not have migrations.
Is there a way to do something alike?
Thank you!

@kraiz
Copy link
Owner

kraiz commented Apr 12, 2017

Hey, django-crontab do not come with models or admins. There's just a subcommand to list current jobs on the console with:

python manage.py crontab show

If you want to keep track on your task execution from within the django admin i suggest to define a model yourself and create a result instance of it in your task.

I indeed experimented with a database-based alternative of django-crontab in django-command-scheduler. It collected success state with stdout/stderr output per defined task. I didn't use it for long and abandoned it in the end while django-crontab received more 'traffic'.

@inspiralpatterns
Copy link
Author

Hey @kraiz, thank you for your answer.
So, how can I do if I would like to see some printed output like print('It does something.') so that I'm sure my function works properly?
Thanks.

@kraiz
Copy link
Owner

kraiz commented Apr 17, 2017

You can define a command suffix to pipe stdout into a file. Have a look at #51

@inspiralpatterns
Copy link
Author

Yes, that is actually what I did.
I looked at CRONJOBS and I implemented format 1:
CRONJOBS = [ ('*/5 * * * *', 'tracking.api.cron.KeywordUpdate', '>> /tmp/scheduled_job.log') ]

and put inside KeywordUpdate method:
self.stdout.write('Successfull end "KeywordUpdate" at %s' % now())

If I prompt python manage.py crontab show I can see:
Currently active jobs in crontab: 599e0f3799cc6b33b2f9e98897e1d6c9 -> (u'*/5 * * * *', u'tracking.api.cron.KeywordUpdate', u'>> /tmp/scheduled_job.log')

but I don't see any log. How is it possible?
Or should I define a CRONTAB_COMMAND_SUFFIX inside settings.py?
I'm quite new to this, sorry for that.

@inspiralpatterns
Copy link
Author

Maybe is this such a case as the one in #14?
I'm using pythonAnywhere as well.

@kraiz
Copy link
Owner

kraiz commented Apr 17, 2017

Oh, then this is probably the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants