Not letting the App go down

I read the FAQ section and noticed this points

  • Projects created by anonymous users expire after 5 days (login via GitHub or Facebook to keep your projects around).
  • Projects sleep after 5 minutes if they are not used.
  • Projects are limited to 4000 requests per hour, with a burst of 4000 requests (subsequent requests will return a 429 “Too Many Requests” response).
  • Projects have a limit of 128MB of space on the container (though things written to ‘/tmp’ don’t count towards that, and we use compression to squeeze the most out of that space). As well as up to 512MB of assets storage.
  • Projects only show up to 100 files in the file tree, the rest get hidden from view but still exist. Using .gitignore to temporarily remove some files from view can help work around this.
  • Similarly, files above 200kb are hidden from the file tree (but still exist), and you’re unable to paste data into the editor above that size too.

I am good with every point except the second point

  • Projects sleep after 5 minutes if they are not used.

Is it somehow possible that the project wont sleep even after 5 mins.
I am making a discord bot and I dont really want that to happen.
Every other points are fine with me though.

Hoping to see a reply about this as soon as possible :smiley:

Apps sleeping is a large reason why we can offer the Glitch service for free, so it’s not something we can turn off. However, we accept that for some use-cases, like bots with no webhooks support, that’s not ideal. It’s possible to expose a route in your app that a web cron service or uptime monitoring service can hit and cause your bot to wake. Doing that every 5 mins or so should do what you want.

Does that means,
If I call my bot codes (using callback or timer in the codes) like every 5 min, it wont go down ?
but yeah with that 4000 request right ?

Yes, and it’ll be ok - the limit is 4000 requests per hour.

Well I am not sure about how to do it again,
I tried making the app busy with some tasks like
setInterval(…,…)
That indeed kept the app busy,
but again it went off after 30 mins.

If you could somehow help me with it. :smiley:

And if futher details help then my app is not a web app insted some worker app (as said in heroku)
As its a discord bot

Hi @Froosty,

the only way to keep your app “awake” is to hit one of its endpoints. So even if your app is a worker, you can start a simple http server and then you can hit your app as Gareth described.

Thanks for your answer,
but In the mean time I would like to ask sorry,
I am new to these stuffs,
mostly the running web and worker apps in VPS.

So if you could help me with it, or if any tutorial for that.
It would be very thankful of you. :smiley:

can someone literally help me with it,
As I said I am new to these stuffs :unamused:

If you’re just using setInterval() to try to call code inside your app, that’s not going to keep it awake. What you would need to do is use setInterval() to cause a delay, and then in the code that runs after the delay, you need to do an HTTP request to one of your own app’s endpoints. That will keep Glitch from shutting the app down.

Here’s an example project that works using this approach: https://glitch.com/edit/#!/twitter-dm-quiz-bot-polling. In it, it exposes the /tweet route to check for new DMs and then sends the appropriate response. You can use uptimerobot.com or a similar service to poll this /tweet endpoint.

1 Like

I had already known that info @Tim, I was just looking for how to do it. :smiley:
and thanks to @Gareth I have got the info now, just need to check it out though.

Hmm I preety much looked into that example @Gareth but there are few problems I am facing

  • firstly my app isnt opening around https://brass-noodle.glitch.me/, here is my app https://glitch.com/edit/#!/twitter-dm-quiz-bot-polling?path=server.js:1:0
    Deleted my app so will be checking out from start and updating the link soon
    (I dunno if this can cause trouble to what I am doing or not but still It should have been opened around there, and also I am not getting any errors in the log)

  • secondly I am really confused about things done there,
    Like is some code inside server.js responsible for keeping the app safe from shutting down ?

Please help me with it,
The more I look into it and more I get confused :frowning:

Here’s the solution I provided which should work for any such app that doesn’t actually need any front-facing app (but hey express.js is already installed so why not)

const http = require('http');
const express = require('express');
const app = express();
app.get("/", (request, response) => response.sendStatus(200));
app.listen(process.env.PORT);
setInterval(() => {
  http.get(`http://${process.env.PROJECT_DOMAIN}.glitch.me/`);
}, 280000);

Should work well enough without the need for any other service. Still testing, though.

3 Likes

I use this service and host on glitch. Works like magic. Thanks for the great service and hard work to the glitch team

1 Like

I have written a module for this: https://www.npmjs.com/package/node-keepalive

Its as easy as:

var keepAlive = require("node-keepalive");
keepAlive();

Hope it helps someone. :+1:

2 Likes

Not a good option in my opinion.

Doesnt work well if anyone wanna use the web app for the project, as your module already consumes the only available port.

Also it is already stated that calling the project from within itself is not the good way to do it.

For that purpose there is uptimerobot.com and that should be prefered using.

It is possible to use the module without conflicting the port like this, please check documentation here: https://www.npmjs.com/package/node-keepalive

var express = require('express');
var app = express();

var keepAlive = require("node-keepalive");
keepAlive({}, app);

// ....... other express endpoints as per your project

var listener = app.listen(process.env.PORT, function() {
  console.log('Your app is listening on port ' + listener.address().port);
});

Yes, a service like https://uptimerobot.com/ is also a good option among other website monitors. Thanks for sharing that.

Anyways, I kept the node-keepalive module versatile and may work for something other than Glitch too. :wink: :grinning:


EDIT (A SOLUTION):

I am using the module in one of my Glitch projects and its working great. This solved the every 5 minutes sleep problem. But, I am sure that it will get shutdown in next 12 hours as mentioned here: Do Glitch projects shut down after every 12 hours?

So, I have installed the module on another Glitch project and using my other module (node-cron-link: https://www.npmjs.com/package/node-cron-link) to call one project with the other, so that if one goes down, the other one will bring it up. :smiley:

This is the code I am using in both projects:

var express = require('express');
var app = express();

var keepAlive = require("node-keepalive");
keepAlive({}, app);

// ....... other express endpoints as per your project

var listener = app.listen(process.env.PORT, function() {
  console.log('Your app is listening on port ' + listener.address().port);
});

var cronLink = require("node-cron-link");
cronLink("https://<other_project_name>.glitch.me/keepalive", {time: 2, kickStart: true});

Just start both projects one after another with a lag of 5-10 minutes.

Hope it helps someone. :+1:

3 Likes