2017-08-02 5 views
1

私はdjangoとawsで初心者です。私はawsで私のdjangoアプリケーションを実行しようとしています。このプロセスはビデオでいくつかのプロセスを作成し、このプロセスが表示されているユーザーが待機するように走っているので、ビデオサイズによっては約3分以上かかりますが、デベロッパーモードでは動作しましたが、awsでは一度2700ms後にプロセスが停止します。どのように私はawsでこのような長いタスクを実行することができますか?awsでdjango long taskを処理する方法

マイビュー:

######################### Call load template ############################### 
def process(request): 
    return render(request, 'testgif.html') 
######################### Process the video and send notification email to user when process is done ################################### 
def getor(request): 
    # get video from s3 bucket mounted on ec2 instance 
    var = Video.objects.order_by('id').last() 
    v = '/mnt/s3/media/videos/' + str(var) 
    # process 
    subprocess.call("./step1.sh %s" % (str(v)), shell=True) 
    #send email notification 
    current_site = get_current_site(request) 
    user = User.objects.values('username').order_by('id').last() 
    us = user['username'] 
    subject = 'Notification of end of process.' 
    message = render_to_string('notify.html', { 
     'us':us, 
     'domain':current_site.domain, 
    }) 
    eml = User.objects.values('email').order_by('id').last() 
    toemail = eml['email'] 
    email = EmailMessage(subject, message, to=[toemail]) 
    email.send() 
    return render(request, 'endexecut.html') 

マイロードテンプレート:

{% extends 'base.html' %} 
{% load staticfiles %} 

{% block content %} 
<div class="container"> 
    <div class="row"> 
     <div class="jumbotron"> 
       <div class="row"> 
       <center> 
        <p> Please wait, your video is processing ! </p> 
        <img src="{% static "images/loading1.gif" %}" id="image-id" width="600" height="400" /> 
       </center> 
       </div> 
     </div> 
    </div> 
</div> 
{% endblock %} 
{% block javascript %} 
<script type="text/javascript"> 
    $.ajax({ 
    url: '/wmark/', 
    type: 'GET', 
    dataType: 'html', 
    success: function(result){ 
      $('#image-id').attr('src', result.image); 
      $('.container').html(result); 
    }, 
    error: function(xhr){ 
      alert(xhr.responseText); //Remove this when all is fine. 
    } 
    }); 
</script> 
{% endblock %} 
+0

どのようにデプロイされますか、ec2インスタンスのみですか、弾力のあるbeanstalkを使用していますか? – user602525

+0

はい、弾力のある豆の豆を使用しています –

答えて

1

ので、ここでの問題は、その要求/応答サイクルは、通常は一旦終了される応答は、あなたが必要とするものをそれほど受けていませんを実行すると、バックグラウンドで実行されるバックグラウンドタスクが開始され、プロセスが完了したときにユーザーに電子メールが送信されます。

私はプロセスを開始して中断してリクエスト/応答サイクルを続けることができるようなceleryのようなものをお勧めします。

ユーザーがページを待っている間に何かを追跡したい場合は、「処理中」の進行状況を更新できるWebソケットも調べます。しかし、この余分な作業は、セロリがビデオの処理を終えた後に電子メールを送信するだけで回避できます。

+0

答えをありがとう、私は2つのセロリのタスクを定義する必要がありますか?ビデオ処理のための最初のものと、電子メール通知のためのもう1つは私の見解では遅れてそれらを呼びますか? –

+0

@ c.cetiそれはそれを解決する一つの方法です。 – myusuf3

関連する問題