process_updates() don't lock globally, but only on unprocessed updates
This commit is contained in:
parent
4e9f34d4a0
commit
e1d27b637c
3 changed files with 16 additions and 6 deletions
|
@ -1,5 +1,6 @@
|
|||
from django.conf import settings
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.db import DatabaseError
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from c3nav.mapdata.tasks import process_map_updates
|
||||
|
@ -9,7 +10,10 @@ class Command(BaseCommand):
|
|||
help = 'process unprocessed map updates'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
process_map_updates()
|
||||
try:
|
||||
process_map_updates()
|
||||
except DatabaseError:
|
||||
print(_('Error: There is already map update processing in progress.'))
|
||||
|
||||
if not settings.HAS_REAL_CACHE:
|
||||
print(_('You have no external cache configured, so don\'t forget to restart your c3nav instance!'))
|
||||
|
|
|
@ -81,8 +81,8 @@ class MapUpdate(models.Model):
|
|||
|
||||
@classmethod
|
||||
def process_updates(cls):
|
||||
with cls.lock():
|
||||
new_updates = tuple(cls.objects.filter(processed=False))
|
||||
with transaction.atomic():
|
||||
new_updates = tuple(cls.objects.filter(processed=False).select_for_update(nowait=True))
|
||||
if not new_updates:
|
||||
return ()
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from django.db import DatabaseError
|
||||
from django.utils.formats import date_format
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import ungettext_lazy
|
||||
|
@ -5,10 +6,15 @@ from django.utils.translation import ungettext_lazy
|
|||
from c3nav.celery import app
|
||||
|
||||
|
||||
@app.task(rate_limit='1/m')
|
||||
def process_map_updates():
|
||||
@app.task(bind=True, max_retries=10)
|
||||
def process_map_updates(self):
|
||||
from c3nav.mapdata.models import MapUpdate
|
||||
updates = MapUpdate.process_updates()
|
||||
try:
|
||||
updates = MapUpdate.process_updates()
|
||||
except DatabaseError:
|
||||
if self.request.called_directly:
|
||||
raise
|
||||
raise self.retry(countdown=30)
|
||||
|
||||
if updates:
|
||||
print()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue