H14 в сети heroku

#python #heroku #telegram-bot #aiohttp #pyrogram

Вопрос:

Здравствуйте, я просто пытался использовать веб-и рабочего бота, я имею в виду что-то вроде

main.py с

 # telegram bot
from pyrogram import Client,filters
Bot = Client(api_id,api_hash,bottoken)

@Client.on_message(filters.command("start")
async def bot_start_cmd(c,m):
   await m.reply_text("Hello I am alive")

if __name__ == '__main__':
   Bot.run() 
 

В другом файле с webapp.py

 from aiohttp import web
from aiohttp import web_fileresponse,streamer
import asyncio,os
WEBFILES_DIRECTORY = "/app/webfiles/"
routes = web.RouteTableDef()

@routes.get('/')
async def index(request):
    return web.Response(text='Hello Babe!')


@streamer
async def file_sender(writer, file_path=None):
     """ This function will read large file chunk by chunk and send it through HTTP without reading them into memory """ 
     with open(file_path, 'rb') as f: 
         chunk = f.read(2 ** 16) 
         while chunk: 
               await writer.write(chunk) 
               chunk = f.read(2 ** 16)

@routes.get('/file/{file_name}')
async def download_file(request): 
    file_name = request.match_info['file_name'] 
    headers = { "Content-disposition": "attachment; filename={file_name}".format(file_name=file_name) } 
    file_path = os.path.join(WEBFILES_DIRECTORY, file_name) 
    if not os.path.exists(file_path): 
        return web.Response( body='File <{file_name}> does not exist'.format(file_name=file_name), status=404 ) 
    return web.Response( body=file_sender(file_path=file_path), headers=headers ) 

async def start_server():
    app = web.Application()
    app.add_routes(routes)
    return app

 

Теперь мне просто нужен был как бот для телеграмм, так и веб на heroku
Поэтому я попробовал Procfile, и он работал только с Интернетом, а рабочему нужен дополнительный динамик, а также был неэффективен, как я хотел
Поэтому я попытался сделать это с помощью docker way

Что-то вроде Dockerfile, как

 FROM ubuntu:20.04
RUN mkdir /app
RUN chmod 777 /app
WORKDIR /app
RUN apt -qq update
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Kolkata
RUN apt -qq install -y git wget curl busybox  python3 ffmpeg python3-pip 
COPY requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt
COPY . .
CMD ["bash","run.sh"]
 

Where run.sh has

 gunicorn webapp:start_server --bind 0.0.0.0:$PORT --worker-class aiohttp.GunicornWebWorker amp; python3 main.py
 

And heroku.yml as

 build:
  docker:
    worker: Dockerfile
run:
  worker: bash run.sh
 

Теперь я развернул его и обнаружил, что работает только бот, и когда я заходил в Интернет, я получал
Что-то вроде

 at=error code=H14 desc="No web processes running" method=GET path="/" host=speedtestdunia.herokuapp.com request_id=c3691fcf-11a3-4ebf-a5bd-8f6aa210fca1 fwd="27.59.96.103" dyno= connect= service= status=503 bytes= protocol=https
 

Ну есть ли какое-нибудь хорошее решение для преодоления этого ???