agendas: refreshing a source is now asynchronous (#50723)
This commit is contained in:
parent
2f72bd8287
commit
e8d2d73ab7
|
@ -21,6 +21,7 @@ import datetime
|
|||
import functools
|
||||
import itertools
|
||||
import math
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
import requests
|
||||
|
@ -33,7 +34,7 @@ from django.contrib.postgres.fields import ArrayField
|
|||
from django.core.exceptions import FieldDoesNotExist
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.validators import MaxValueValidator, MinValueValidator
|
||||
from django.db import models, transaction
|
||||
from django.db import models, transaction, connection
|
||||
from django.db.models import Count, Q, Case, When
|
||||
from django.template import engines, Context, Template, TemplateSyntaxError, VariableDoesNotExist
|
||||
from django.urls import reverse
|
||||
|
@ -1616,6 +1617,17 @@ class TimePeriodExceptionSource(models.Model):
|
|||
return _('Exception')
|
||||
|
||||
def refresh_timeperiod_exceptions(self, data=None):
|
||||
if 'uwsgi' in sys.modules:
|
||||
from chrono.utils.spooler import refresh_exception_source
|
||||
|
||||
tenant = getattr(connection, 'tenant', None)
|
||||
transaction.on_commit(
|
||||
lambda: refresh_exception_source.spool(
|
||||
source_id=str(self.pk), domain=getattr(tenant, 'domain_url', None)
|
||||
)
|
||||
)
|
||||
return
|
||||
|
||||
self.refresh_timeperiod_exceptions_from_ics(data=data)
|
||||
|
||||
def refresh_timeperiod_exceptions_from_ics(self, data=None, recurring_days=600):
|
||||
|
|
|
@ -14,3 +14,32 @@
|
|||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from django.db import connection
|
||||
|
||||
from uwsgidecorators import spool
|
||||
|
||||
from chrono.agendas.models import ICSError, TimePeriodExceptionSource
|
||||
|
||||
|
||||
def set_connection(domain):
|
||||
from hobo.multitenant.middleware import TenantMiddleware
|
||||
|
||||
tenant = TenantMiddleware.get_tenant_by_hostname(domain)
|
||||
connection.set_tenant(tenant)
|
||||
|
||||
|
||||
@spool
|
||||
def refresh_exception_source(args):
|
||||
if args.get('domain'):
|
||||
# multitenant installation
|
||||
set_connection(args['domain'])
|
||||
|
||||
try:
|
||||
source = TimePeriodExceptionSource.objects.get(pk=args['source_id'])
|
||||
except TimePeriodExceptionSource.DoesNotExist:
|
||||
return
|
||||
try:
|
||||
source.refresh_timeperiod_exceptions_from_ics()
|
||||
except ICSError:
|
||||
pass
|
||||
|
|
Loading…
Reference in New Issue