R
Railway•11mo ago
Girish

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
Percy
Percy•11mo ago
Project ID: N/A
Brody
Brody•11mo ago
what command do you want to run?
Girish
GirishOP•11mo ago
python manage.py send_maturity_emails
Brody
Brody•11mo ago
can you show me a screenshot of your railway project
Girish
GirishOP•11mo ago
No description
Girish
GirishOP•11mo ago
is this what you meant by project ?
Brody
Brody•11mo ago
yep exactly when you run python manage.py send_maturity_emails does that code do its task and then exit?
Girish
GirishOP•11mo ago
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
Brody
Brody•11mo ago
but it exits after the task is done, correct?
Girish
GirishOP•11mo ago
is there an explicit way i can check that
Brody
Brody•11mo ago
oh you didnt write the code?
Girish
GirishOP•11mo ago
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
Brody
Brody•11mo ago
run that command locally, after it sends the email does it stay running or does it return you to the terminal?
Girish
GirishOP•11mo ago
one sec It returns
Girish
GirishOP•11mo ago
No description
Girish
GirishOP•11mo ago
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
Brody
Brody•11mo ago
but your repo is the equivalent to your local INVESTMENTS folder right?
Girish
GirishOP•11mo ago
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
Brody
Brody•11mo ago
what have you set the start command of the mails service to? thats to be expected, that shell is a local shell
Girish
GirishOP•11mo ago
No description
Brody
Brody•11mo ago
have you attached your github repo to that service?
Girish
GirishOP•11mo ago
No ,
Brody
Brody•11mo ago
well theres your problem! no code to run
Girish
GirishOP•11mo ago
If i attach the github repo , then the entire app keeps getting deployed every 5 minutes
Brody
Brody•11mo ago
nope, only that start command is ran
Girish
GirishOP•11mo ago
oh let me try it now Sorry , i didnt see where i was 🙂
Brody
Brody•11mo ago
can you show me a screenshot of the mails service variables?
Girish
GirishOP•11mo ago
So yeah , its partially working sure
Girish
GirishOP•11mo ago
No description
Brody
Brody•11mo ago
I feel like a mail client would need more information than that for authentication?
Girish
GirishOP•11mo ago
I have only these 2 env variables defined in my local as well
Brody
Brody•11mo ago
what is your mail service you are using?
Girish
GirishOP•11mo ago
send-grid
Brody
Brody•11mo ago
show me the logs of the last job that ran?
Girish
GirishOP•11mo ago
other things are in my code, this is just a side project so i have not encrypted the from address etc
Girish
GirishOP•11mo ago
No description
Brody
Brody•11mo ago
looks like there could be errors but you aren't logging any errors
Girish
GirishOP•11mo ago
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
Brody
Brody•11mo ago
oh well you don't even have a database in your project?
Girish
GirishOP•11mo ago
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
Brody
Brody•11mo ago
right but I'm not seeing a database here unless you are hosting your database off of railway?
Girish
GirishOP•11mo ago
No description
Brody
Brody•11mo ago
are you using sqlite?
Girish
GirishOP•11mo ago
YESS
Brody
Brody•11mo ago
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
Girish
GirishOP•11mo ago
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
Brody
Brody•11mo ago
regardless, I highly highly recommended you moving away from sqlite and instead use postgres
Girish
GirishOP•11mo ago
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
Brody
Brody•11mo ago
nope, I'm saying you should use postgres as your database
Girish
GirishOP•11mo ago
ok
Brody
Brody•11mo ago
I promise you that it is going to be far easier to use a postgres database
Girish
GirishOP•11mo ago
ok sure I will explore that , pretty new to development , thanks ..this is the first webapp am creating in my life still learning
Brody
Brody•11mo ago
I'm not saying it's going to magically fix your code, but it will definitely be a step in the right direction
Girish
GirishOP•11mo ago
ok
Want results from more Discord servers?
Add your server