Forums

No file returned from scheduler

I wrote a custom command designed to run daily with PA’s scheduler and return a csv file. However, I couldn’t get a file to return and only got the following message when I checked my scheduler log:

Completed task, took 1.00 seconds, return code was 0.

Besides the log message, no error message was given. I ran the script from bash console, and it works fine from there. I also changed the path of the output file from relative to absolute, but it didn’t solve the problem. Any idea what’s causing this?

Just to confirm, do you mean your scripts writes a csv file to disk?

And what was the command that you used from the bash console?

Yes, the csv file is saved to the same folder where manage.py is. The command I used is:

>python manage.py write_csv

where "write_csv" is my custom script

Are you using a virtualenv? If not, then your scheduled task should be something like python path-to-your-manage.py write_csv

I had a virtualenv set up on PA, but it wasn't active when I enter the command, and I didn't have to enter the absolute path for my script to work.

What is the command that you are using for your scheduled task?

I pasted the following into the scheduler; no argument is needed for my script:

/home/cqcum6er/my-first-blog/blog/management/commands/write_csv.py

If you run the Python file containing a Django management command, then it will do nothing and simply exit with no error (ie. with return code 0).

You need to use Django's manage.py command to run it. Just put the command that you type into the bash console into "run" part of the scheduled task setup, eg.

cd /home/cqcum6er/my-first-blog/; python manage.py write_csv

Thank you all, the script is running correctly now:)

Excellent, thanks for confirming!