How to run Dash app on Heroku in the background job?

This standard dash app:

import dash_table
import pandas as pd
import dash
import psycopg2

conn = psycopg2.connect(
    port = 5432,

statment= f"""
select a,b,c,d, count(c) as count_c
from public.table
group by 1,2,3,4
order by 5 desc
df= pd.read_sql_query(statment ,con=conn)

app = dash.Dash(__name__)

app.layout = dash_table.DataTable(
    columns=[{"name": i, "id": i} for i in df.columns],

if __name__ == '__main__':

The problem is that SQL query running 1-2 minutes when Heroku limited runtime only to 30 seconds, and after this get error ‘timeout expired’

The solution is to run the app in the background job.
By Heroku Help Background Tasks in Python with RQ | Heroku Dev Center not so clear how to combine this with Dash App.

Can anyone help how to integrate this with the Dash App?