Unable to execute cron commands
Guys , I have a django app deployed in railway. I want to schedule a cron job that runs a certain command on my projects directory . I created a service and scheduled the cron job but the service is not running and I am not sure how I can point the command to run at my projects' directory in railway. Can anyone help
54 Replies
Project ID:
N/A
what command do you want to run?
python manage.py send_maturity_emails
can you show me a screenshot of your railway project
is this what you meant by project ?
yep exactly
when you run
python manage.py send_maturity_emails
does that code do its task and then exit?yes it doesnt have any rogue instances / components. Its just a python command that executes a .py file
In my local. i am able to navigate to my porject directory and run this command and an email is sent
but it exits after the task is done, correct?
is there an explicit way i can check that
oh you didnt write the code?
Yes brody I did. So to give you better context, this is a .py file that has a method which sends out emails to users. Thats it. So yes, the code exits
It just calls a function
run that command locally, after it sends the email does it stay running or does it return you to the terminal?
one sec
It returns
Thats my local , here i am bale to navigate to my INVESTMENTS folder and run this command. I am not able to do this in railway server
So i configured mails service giving that command , but I do not know where it is executing it , i do not see any logs
but your repo is the equivalent to your local INVESTMENTS folder right?
yes same
my github repo = INVESTMENTS in my local
I tried using the railway CLI , the railway shell command
but when i run the command in the shell it executes in local and not in the railway server
what have you set the start command of the mails service to?
thats to be expected, that shell is a local shell
have you attached your github repo to that service?
No ,
well theres your problem!
no code to run
If i attach the github repo , then the entire app keeps getting deployed every 5 minutes
nope, only that start command is ran
oh let me try it now
Sorry , i didnt see where i was 🙂
can you show me a screenshot of the mails service variables?
So yeah , its partially working
sure
I feel like a mail client would need more information than that for authentication?
I have only these 2 env variables defined in my local
as well
what is your mail service you are using?
send-grid
show me the logs of the last job that ran?
other things are in my code, this is just a side project
so i have not encrypted the from address etc
looks like there could be errors but you aren't logging any errors
hmmm, but exact same thing is running in my local, My doubt is--> When the command is run , my code checks my DB for a particular table called investments, And if there is an investment that has maturity date= Today then it sends an email . Currently in the environment i have deployed I have one record that matures today but I am doubting if this service is checking the DB of my app or if its checking the db tables created when i connected the repo to the service
I saw the entire db table creation scripts run
oh well you don't even have a database in your project?
I do , I am able to create users and add investments in the railway pre-prod environment
I get an email thats auto triggered when the user signs up
right but I'm not seeing a database here
unless you are hosting your database off of railway?
are you using sqlite?
YESS
are you aware that between each deploy the container gets wiped and with that so does your sqlite database since you are not using a volume to store the database
oh ! but I am able to login with the user which i created a caouple of deployments ago. The user is also stored in DB tables. LEt me cross check that , just to be sure
regardless, I highly highly recommended you moving away from sqlite and instead use postgres
ok
and you say I should use Volume to store the DB eh?
Ok Brody looks like i have some more to learn here. Thanks much . I will explore this further
nope, I'm saying you should use postgres as your database
ok
I promise you that it is going to be far easier to use a postgres database
ok sure I will explore that , pretty new to development , thanks ..this is the first webapp am creating in my life still learning
I'm not saying it's going to magically fix your code, but it will definitely be a step in the right direction
ok