-
Notifications
You must be signed in to change notification settings - Fork 7
Keeping-Server-Awake #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
mferryRV
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added some thoughts on how you can simplify. Doing this with JS is likely overkill, as command line tools will not require any dependencies to accomplish the same task.
Make sure you run this workflow from a branch before you merge anything. Don't merge until you have it running successfully from the branch.
| } | ||
| } | ||
|
|
||
| ping("starter-kit-al84.onrender.com"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be an environment variable
|
|
||
| on: | ||
| schedule: | ||
| - cron: "*/10 * * * *" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this frequent enough? Need to make sure you account for variations in cronjob startup time. If it shuts down after 15 min of inactivity then this 10 min timer should be fine. If it shuts down after 10 min of inactivity, you should shorten a bit e.g. 8 min
| uses: actions/checkout@v2 | ||
|
|
||
| - name: Run Ping Script | ||
| run: /usr/bin/node /server/serverPing.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to run npm i to install dependencies? Should these dependencies include the full project or just the two from pingServer?
| @@ -0,0 +1,15 @@ | |||
| const child_process = require("child_process"); //to run command-line tools | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you really need to run JavaScript for this? Or could you just run ping $URL on the command line directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Matthew, thank you for all your comments. Really appreciate it! I think the only dependencies that should be included are the ones from pingServer. For running ping $URL on the command line directly, I wasn't sure how to do it, so I will have a read and change it. If you have any documentation recommendation that would be great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing @munozirianni1988 - we're getting to the meat and potatoes of software engineering now!
I would look at curl for making HTTP requests from the command line, e.g.:
curl https://google.com
To make sure the response is good, you could look at HTTP status codes.
To see the requests that curl is making - or any app for that matter - you can use HTTPdump. It allows you to create a fake website or API endpoint and see what your code is sending on requests.
I'd also recommend looking at the monthly usage limits for Render to make sure that you can run the app all the time without running out of usage. You get 750 hours / month (31.25 days) but if those hours cover both the server and the database, you would only get 15.125 days for those two instances.
If you can't run it 24 hours a day, I'd recommend running your cronjob only during the 12 hours you think it will be most useful (e.g. 8am - 8pm every day, or 14 hours a day but it's off on Sundays). You could add additional optimisation by caching the database response in the API server, so we only hit the database once on startup (e.g. with node-fetch-cache). This would allow the database to be off most of the time, and the data only changes on deployment so it wouldn't get out-of-date.
Also make sure you look at the Github Actions free tier limits to make sure your cronjob will run all month. It may also help you ask questions like "Is it better to have a new job every 10 minutes or a 4-hour job that does something every 10 minutes?"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wow! Like we say in Cuba: el mango del arroz con mango! hahaha. I will dive into all this information as soon as I get home today. I wouldn't have a clue as to where to start looking/researching for all this, and all I was finding were very long complicated solutions. Thank you very much @mferryRV !
Naming Rules
Name your PR like this: ISSUENUMBER-TITLE-YOURNAME
Description
Write a summary of your change. Explain why you have made it.
Related to
Make sure you include the issue number with a hash sign # so Github can link this PR to the right issue, like this:
Fixes #1
Checklist: