Y
Y
yahabrovec2019-06-13 18:11:41
Python
yahabrovec, 2019-06-13 18:11:41

How to host a non-webserver script on hostings like heroku?

Hello.
I recently decided to write a "news aggregator bot" and things like that. He should email me the results every hour. The code is ready but there is a problem. Initially, I tried to make a Flask web server out of it and run it through gunicorn for later integration with heroku or any other hosting of a similar type. But I came to the conclusion that, in principle, I do not need any web muzzle, it will only interfere with work and devour the RAM. I tried to run two threads, in one the Flask server itself in the other my script, but this is a high-class crutch that will soon be covered anyway. I don’t know how the architecture of such applications is built in such cases, because heroku assumes that the script will be launched by any wsgi server immediately upon deployment, and a simple launch like 'python server.py' will immediately be put after the first development. And I would like it to hang there and not touch anyone. In fact, all bots are too small in size and memory consumption, I would not want to pay even the cheapest vds for 400 rubles a month. I feel there is some way out of the situation.

UPD
Heard about Celery and Redis broker. But then the size of the project triples. I don't think this option will work for me.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
prostoprofan, 2019-06-13
@prostoprofan

There is a VPS and for $1 in Europe, 512MB of memory, what prevents you from running the script in the background via screen ?

R
Robur, 2019-06-13
@Robur

will immediately be laid after the first working off.

If your script is designed to run forever, then "working out" will not happen.
Heroku does some checks to see if the server is up, and timeouts it if not, but they can probably be disabled.
Try one of these:
- read the docs about how heroku monitors the process, maybe you can set up your own checks
- maybe worker instead of web
- you can just open the right port to calm heroku, you don’t need flask for this or something else that will do - something minimally simple, which listens to the port and does nothing (or gives an empty response if Herok needs HTTP). There is no reason for such a scheme to “close soon”.

N
Nikita Belov, 2017-07-27
@mr-alexey

Cycle. We make a selection using the pdo\mysqli driver. After the fetch, we write the data to the fetch_assoc() array in the while loop, and in it we also write the data to .txt using file_put_contents.
The easiest option for a beginner.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question