django 3rd party API 事件循环?

发布于 2025-01-15 11:19:19 字数 340 浏览 2 评论 0原文

我对后端开发很陌生,所以请原谅我的无知。

我需要将 Django 后端连接到第 3 方 API,以从 GPS 跟踪器获取实时位置数据。这需要在服务器端完成,因为它会触发其他事件,因此它不能只在浏览器中运行。

请问这样做的最佳方法是什么?到目前为止,我已经想到了类似事件循环的东西,每 60 秒调用一次 API,但是我可以在单独的线程上运行它吗?这是最好的做法吗?

是否可以从我的后端向第 3 方执行类似 Websocket 的操作?保持这些数据更新的最佳方法是什么?

最后,像这样的解决方案如何扩展,如果我有 5,000 个车辆跟踪器都需要更新怎么办?

任何建议将不胜感激。

谢谢。

I'm quite new to back-end development so please forgive my ignorance.

I need to connect my Django backend to a 3rd party API to fetch live location data from GPS trackers. This needs to be done server side as it triggers other events, so it can't just be run in the browser.

What's the best way to go about doing this please? So far I have thought of something like an event loop which calls the API every 60 seconds, but can I run this on a separate thread for example? Is that even the best thing to do?

Is it possible to do something like a websocket form my backend to the 3rd party? What's the best way of keeping this data updated?

Finally, how does a solution like this scale, what if I had 5,000 vehicle trackers which all needed updating?

Any advice would be greatly appreciated.

Thank you.

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

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

发布评论

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

评论(1

轻拂→两袖风尘 2025-01-22 11:19:19

您可以创建一个空网页来触发后端逻辑,

并配置 cronjob 每隔 60 秒在此页面上发送一次 get 请求,

默认情况下它也会在单独的线程上启动。

您可以扩展它,例如您有 5000 辆车,只需将此后端逻辑拆分为两个不同的函数(每个 2500 辆车)(这将由两个不同的 get 请求触发),并且它们将在单独的线程上独立工作)

或者您可以使用 asyncio 将逻辑拆分到一个函数中,并且仍然异步且单独地启动它

you might create an empty webpage which triggers your backend logic,

and configure cronjob which would send get request on this page every 60 seconds,

it also will be started on separate thread by deafult.

you might scale it for example you have 5000 vehicles, just split this backend logic on two different functions(each 2500 vhicles) (which would be triggered by two different get requests), and they would work independant, on separate threads)

or you can use asyncio to split your logic inside one function, and still start it asynchronously and separatly

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文