python - flask页面提交数据服务端独立处理数据思路请教
怪我咯
怪我咯 2017-04-17 17:31:23
0
3
373

一个比较简单的功能问题请教
现在实现的功能是这样的:
页面指定一个项目以及调节一个版本号

提交完之后服务端开始处理

@qq.route('/updateqq',methods=['GET','POST'])
def updateqq():
    versionform = VersionForm()
    rsyncwork = rsyncPro()
    if versionform.validate_on_submit():
        session['proId'] = request.form.get('selectid')
        session['versionNum'] = versionform.version.data
        print session.get('proId')
        print session.get('versionNum')

        #获取项目各个信息
        project_name = proDic.get('%s' %session.get('proId'))['pro_name']
        project_local_dir = proDic.get('%s' %session.get('proId'))['pro_dir']
        project_online_dir = proDic.get('%s' %session.get('proId'))['ol_dir']
        project_ip = proDic.get('%s' %session.get('proId'))['pro_ip']
        project_cmd = proDic.get('%s' %session.get('proId'))['pro_up']
        print project_name,project_local_dir,project_online_dir,project_ip,project_cmd
        
        #执行svn操作
        rsyncwork.get_version(project_local_dir)
        rsyncwork.online_laste(project_online_dir,project_name)
        up_version = int(session.get('versionNum'))
        rsyncwork.get_version(project_local_dir)
        return redirect(url_for('qq.updateqq'))
    return render_template('qq/updateqq.html',
                           prodict = pronameDict(),
                           versionform = versionform)

服务最终处理一些update,rsync,commit等一些操作内容,由于每次更新的内容不一定,执行这个的时间也不一定,当服务端执行这些时候,页面就会处于一直在加载的状态,所以我想把服务端处理的这些单独剥离出来,最终的实现功能就是,当页面提交完之后,前端就算处理完了,返回到原始的表单页面,服务端自己独立出来这些内容,而不是前端要等服务端处理完才跳转回到原来的页面。

这种的是要怎么的一种处理思路的?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(3)
Ty80

This cannot be done by relying on flask. The model of flask is: request-response. And your need is independent of this process.

Simply put, you need a system to help you handle asynchronous tasks. Considering that you use Python, I recommend celery.

小葫芦

Easier solution:

  1. front-end submission information

  2. The view layer saves the information to the database or somewhere, including who, for whom, what to do, and sets the initial status to incomplete

  3. Run a background script, loop endlessly, continuously read unfinished tasks from the place saved above, execute specific tasks, and mark them as completed.

PHPzhong

You are referring to flask's asynchronous message response, which requires the use of a message queue. The function of the message queue is to only cache the user's current request but not actually process it. It will derive the message to the corresponding worker for processing. You You can take a look at Flask-Celery, and also often use Flask-RQ

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template