Reputation: 21015
I got some cron jobs that i wanna test, where should i out them, how can i run them with rails commands and if the got some dependencies like files and stuff how can i load their fixture?
to be more concrete lets say i got a rb file thats reads a file from a the app folder, do some parsing, and writes stuff to db.
where to put the test and how to connect it with rails?
Upvotes: 0
Views: 1210
Reputation: 1085
My method is to create a folder called app/jobs, then name the classes in the folder accordingly. The jobs are then called using script/rails runner. The runner interface loads rails and you have access to all of your models.
class SomeOddJob
def run
#do something
end
end
from your cron job you'd run the job like this (in production mode):
0 5 * * * /path/to/script/rails runner -e production "SomeOddJob.run"
Upvotes: 2