I’m following along this guide and am able to pass along a command to my app via the schedule.json file, however, the fly logs on my main app indicate that the command is invalid.
I’m trying to run a a task via rails runner:
"/rails/bin/rails runner RailsService.new().test"
Fly logs on the main app shows:
ERROR Error: failed to spawn command: /rails/bin/rails runner RailsService.new().test: No such file or directory (os error 2)
does `/rails/bin/rails` exist and is it executable?
I’ve tried multiple versions of rails runner and bin/rails runner to no success…
cron-manager is a separate machine running on a separate image; your Rails app is not running there. I’d need to know more of what you are trying to do to help you further, but perhaps what you are looking for is to have your cron job make a request to your Rails app? If so, perhaps curl could help…
Okay, maybe I didn’t explain correctly, I’ll try to further elaborate.
I have two apps on fly, let’s call them “rails-app” and “cron-app”.
I am trying to run a rails runner command on the rails-app, via the cron-app. I am able to see the command running on the rails-app.log, meaning that the cron-app is successfully sending the command to the rails-app. However, I get the following error (on the rails-app.log):
ERROR Error: failed to spawn command: /rails/bin/rails runner RailsService.new().test: No such file or directory (os error 2)
does `/rails/bin/rails` exist and is it executable?
I know this will sound annoying, but are you sure that your command is running on the Rails machine?
Inside the first square brackets in log lines is the machine number.
The error message you are getting says that /rails/bin/rails is not found, and the Dockerfile you provided places your rails app in the /rails directory. The possibilities are that this command is not running on the rails machine, or that your app does not contain a bin/rails file, or that file is not marked as executable.
The last possibility generally only affects Windows users, and is typically handled when the Dockerfile is generated. The fix is to add the following lines:
Okay this is helpful…
On my rails-app, the machine number that appears in the logs does not appear in any of my machines in my Sign in to Your Account · Fly…
It also changes after each failed cron-job… (It seems)
The image your cron-job Machine is running is livebook:0.11.4 This image is used within the example config, so i’m guessing that’s where the problem lies. If you want to run a Rails command, you will need to configure your cron-job to use the appropriate image.
I should note though that if this is the only cron-job you need to run, there are Rails specific cron gems you could use that could make things easier for you. E.G. whenever.
Interesting, I didn’t know about this. I was previously doing this with a fly redis-server and found it to be too costly. I will look into “whenever”, however i have a few cron jobs I will be running.
Regardless, we are up and running as of now, I thank you both for your time and help