0

MyProj/myproj/urls.py:

from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    url(r'^accounts/login/$', 'django.contrib.auth.views.login'),
    url(r'^accounts/logout/$', 'django.contrib.auth.views.logout_then_login'),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^', include('apps.data.urls')),
)

MyProj/apps/data/urls.py:

from django.conf.urls import patterns, url

urlpatterns = patterns('',
   url('^tasks/sync_database/', 'apps.data.views.sync_database'),
)

MyProj/apps/data/views.py:

from .tasks import sync_database as sync_database_task
from django.shortcuts import redirect

def sync_database(request):
    sync_demand_stacks_task()
    return redirect('/')

The task takes about 5 minutes to run. I expect that when I visit the url localhost:8000/tasks/sync_database/ that the web page should block for the duration of the time it takes the task to run, then show me the home page at url localhost:8000/.

This does happen, but instead of running the task just once it runs it twice. What gives?

EDIT: I see this output in the console at the very end of the first request:

127.0.0.1 - - [20/Feb/2014 15:18:43] "GET /tasks/sync_database/? HTTP/1.1" 500 -

I'm wondering where this URL with a question mark appended comes from.

tadasajon
  • 14,276
  • 29
  • 92
  • 144
  • What happens after the 1st hit? – user590028 Feb 20 '14 at 19:30
  • After the first hit it just immediately starts over as though I went to the same URL again. – tadasajon Feb 20 '14 at 19:33
  • Where is the URL pattern to match `localhost:8000/`? – arocks Feb 20 '14 at 19:35
  • All my URL patters are included in the example above. I'll try adding one that just matches `localhost:8000/` – tadasajon Feb 20 '14 at 19:40
  • Because your task is take long time(about 5 minutes to run), your browser may request again (and again) to that url, check your requests of your browser for that, from within browser for example by `firebug`, or from `log` of your web server. – Omid Raha Feb 20 '14 at 19:55
  • Omid could be right. Independent from that I think it would be best practice to run this task asynchronously like suggested here at http://stackoverflow.com/questions/12597152/asynchronous-view-with-client-update-for-long-running-processes-views. – timo.rieber Feb 20 '14 at 20:49
  • Yes, I am using celery and this task does run asynchronously. I'm just doing it this way for some testing and development purposes. Celery is giving me some difficulty -- perhaps you can help debug your own suggestion by taking a look at my celery-related question here: http://stackoverflow.com/questions/21920323/django-1-6-rabbitmq-3-2-3-celery-3-1-9-why-does-my-celery-worker-die-with – tadasajon Feb 20 '14 at 21:47

1 Answers1

0

Getting my favicon to work correctly has apparently made the problem disappear.

tadasajon
  • 14,276
  • 29
  • 92
  • 144