Forums

Cron limits

Just want to ask a quick question. I see that there are some limits on how many cron jobs you can have. I have an app that adds cron job each time user ads certain info and at the beginning will have more than 100 cron jobs (running ftp at certain hour and retreiving a file) and later even more. Is this doable on pythonanywhere?

Can someone explain what it means 20, hourly or daily scheduled tasks on Web developer plan.

Your best bet would be a single Scheduled Task that worked through a list of files to retrieve rather than a different one for each file to retrieve.

A scheduled task can be run either hourly or daily and you can have 20 of them.

How to set up a single Scheduled Task that worked through a list of files? Can you give a example?

You could do it pretty much any way you wanted. Let's say that there was a fairly small number of tasks -- then you could specify them on the command line by scheduling

python3.6 /home/bloem/something/script.py /home/bloem/somethingelse/file1.txt /home/bloem/somethingelse/file2.txt /home/bloem/somethingelse/file3.txt

...then in the script:

import sys

for filename in sys.argv[1:]:
    do_something(filename)

Alternatively, if there were a lot of files, and the set of files changed regularly, you could create a file which contained the list of paths to those files, one per line. You'd schedule

python3.6 /home/bloem/something/script.py /home/bloem/somethingelse/filelist.txt

where the file /home/bloem/somethingelse/filelist.txt contained

/home/bloem/somethingelse/file1.txt
/home/bloem/somethingelse/file2.txt
/home/bloem/somethingelse/file3.txt

....and so on, then in your script you would do this:

import sys

with open(sys.argv[1], "r") as f:
    file_list = f.read().split("\n")

for filename in file_list:
    do_something(filename)

There are lots of other possibilities.

Thanks. Why using a or more txt-files for file1, file2 and file3? Can this also be py-files?

Sure. If you want to execute some python files, you can use one of the subprocess methods.

I tried to long version. List.py:

import sys

with open(sys.argv[1], "r") as f:
    file_list = f.read().split("\n")

for filename in file_list:
    do_something(file_list.py)

And got this messagger:

list.py, line 7, in <module>
    do_something(file_list.py)
NameError: name 'do_something' is not defined

How to solve this?

There is nothing to solve. Giles was indicating with that placeholder that that is the place where you need to put your code to do whatever it is that you want to do with the data in the file. do_something is not defined because you have not defined it yet.