与Web服务器或网页上的后端作业进行通信 [英] Communicate with backend job from web server or web page

查看:79
本文介绍了与Web服务器或网页上的后端作业进行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行Linux的设备"(由于缺乏更好的描述).

I have an "appliance" (for lack of better description) running linux.

当前,我将进入工作框以启动作业.这对我的用户来说还不够友好,因此我将使用一个简单的Web UI来启动脚本.作业运行时间从10秒到几个小时不等. Web UI需要反映作业的状态.

Currently I ssh into the box to launch jobs. This isn't friendly enough for my users, so I'm putting together a simple web UI to launch the script. A job runs for anywhere from 10 seconds to several hours. The web UI needs to reflect the status of the job.

过去,我已经通过在服务器上运行守护程序来解决类似的问题,该守护程序监视假脱机目录(或db表)中的新作业请求,生成一个进程,监视该进程,并提供有关Web UI的信息.数据库表或状态文件.然后,Web UI将作业请求放到假脱机目录(db)中,并偶尔检查状态文件(db).对于这个任务,这可能是多余的.

I've solved similar problems in the past by running a daemon on the server that watches a spool directory (or db table) for new job requests, spawns a process, monitors the process, and provides info for the web UI in a db table or status file. The web UI then drops job requests into a spool dir (db) and occasionally check the status file (db). This might be overkill for this task.

对于当前任务,我正在考虑从cgi派生该作业,并偶尔检查该作业在进行中或退出时写入的状态文件.

For the current task, I am considering spawning the job from the cgi and occasionally checking a status file that the job writes as it progresses or exits.

我的问题:是否有更好的方法(更简单/更快速地编写/更强大)来做到这一点?我是否应该了解现有的模式或工具?

My question: is there a better (simpler/faster-to-write/more robust) way to do this? Are there existing patterns or tools that I should know about?

(Python解决方案是理想的选择.)

(Python solutions are ideal.)

谢谢.

推荐答案

我在许多项目中都这样做.一个网络应用程序(主要是Python/CGI),它产生一个单独的python脚本(使用子进程),该脚本立即

I do this in a number of projects. A web-app (mostly Python/CGI) that spawns a separate python script (using subprocess) which instantly daemonizes itself to do the work. The web-app then continues to issue AJAX requests to check on the daemon process progress (I use simple txt files for communication, database would probably be better). One nice touch is to have the daemon email the end user once it finishes (with a link to retrieve results). This way the user can close their web browser on those jobs that take hours.

这篇关于与Web服务器或网页上的后端作业进行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆