'H14 in heroku web

Hello I was just trying to use web and worker based bot I mean something like

main.py with

# 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() 

On the other file with 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

Now I just wanted both telegram bot and web on heroku So I tried Procfile and it only worked with web and worker needs an extra Dyno and also wasn't efficient as I wanted So I tried to do it with docker way

Something like Dockerfile as

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 & python3 main.py

And heroku.yml as

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

Now I deployed it and found that only bot was running and when I access Web I used to get Something like

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

Well any good solution to overcome this ???



Solution 1:[1]

Just Change worker to web in heroku.yml

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1