-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| name: Ping Server | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: "*/10 * * * *" | ||
|
|
||
| jobs: | ||
| ping: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v2 | ||
|
|
||
| - name: Run Ping Script | ||
| run: /usr/bin/node /server/serverPing.js | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need to run |
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| */10 * * * * /usr/bin/node /server/serverPing.js |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| const child_process = require("child_process"); //to run command-line tools | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 To make sure the response is good, you could look at HTTP status codes. To see the requests that 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?"
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ! |
||
| const util = require("util"); //to handle asynchronous functions | ||
|
|
||
| const exec = util.promisify(child_process.exec); | ||
|
|
||
| async function ping(hostname) { | ||
| try { | ||
| const { stdout, stderr } = await exec(`ping -c 3 ${hostname}`); | ||
| return { stderr, stdout }; | ||
| } catch (err) { | ||
| return err; | ||
| } | ||
| } | ||
|
|
||
| ping("starter-kit-al84.onrender.com"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be an environment variable |
||
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