Dash - 在服务器端运行回调

发布于 2025-01-12 09:06:33 字数 268 浏览 6 评论 0原文

早上好,

我在 Dash 中创建了一个回调,它可以充当调度程序。 每 10 分钟(在间隔组件的帮助下),我的回调就会运行以从服务器获取数据并更新我在应用程序中使用的 csv 文件。

问题是只有当我打开网页时才会调用我的回调。一旦我关闭页面,调度程序就会停止并在我再次打开页面时再次运行。

由于更新数据的数据过程有时可能很长,因此我希望调度程序始终每 10 分钟运行一次并获取数据。

我假设回调是客户端进程,对吧?那么如何让它在服务器端运行呢?

谢谢你,

Good morning,

I have created a callback in Dash that makes the job of a scheduler.
Every 10 minutes (with the help of an interval component), my callback is running to fetch the data from a server and to update the csv file that I use in my app.

The problem is that my callback is called only when I have the webpage opened. As soon as I close the page, the scheduler stops and runs again when I open the page again.

As the data process of updating data can be long sometimes, I want the scheduler to always run and fetch the data every 10 minutes.

I assume that a callback is a client side process right? So how can I make it run in server side?

Thank you,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如若梦似彩虹 2025-01-19 09:06:33

达世币可能不是这个问题的正确解决方案。我认为在一个简单的 .py 脚本文件中设置此作业所需的 Python 代码,并设置一个 cron 作业每 10 分钟运行该脚本会更有意义。

Dash is probably not the right solution for this. I think it would make more sense to set up the Python code you need for this job in a simple .py script file, and set a cron job to run that script every 10 min.

鸵鸟症 2025-01-19 09:06:33

谢谢@coralvanda 的帮助。

我最终在容器 A 中编写了一个 python 脚本,每 10 分钟调用一次容器 B。容器B正在获取数据。

它完成了工作。

import schedule
import time
import docker

def worker_restart():
    client = docker.from_env()
    container = client.containers.get('container_worker')
    container.restart()

schedule.every(10).minutes.do(worker_restart)
while True:
    schedule.run_pending()
    time.sleep(1)

Thank you @coralvanda for the help.

I finally did a python script in my container A that calls the container B every 10 minutes. The container B is fetching the data.

It makes the job.

import schedule
import time
import docker

def worker_restart():
    client = docker.from_env()
    container = client.containers.get('container_worker')
    container.restart()

schedule.every(10).minutes.do(worker_restart)
while True:
    schedule.run_pending()
    time.sleep(1)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文