0003-agendas-refreshing-a-source-is-now-asynchronous-5072.patch
chrono/agendas/models.py | ||
---|---|---|
21 | 21 |
import functools |
22 | 22 |
import itertools |
23 | 23 |
import math |
24 |
import sys |
|
24 | 25 |
import uuid |
25 | 26 | |
26 | 27 |
import requests |
... | ... | |
33 | 34 |
from django.core.exceptions import FieldDoesNotExist |
34 | 35 |
from django.core.exceptions import ValidationError |
35 | 36 |
from django.core.validators import MaxValueValidator, MinValueValidator |
36 |
from django.db import models, transaction |
|
37 |
from django.db import models, transaction, connection
|
|
37 | 38 |
from django.db.models import Count, Q, Case, When |
38 | 39 |
from django.template import engines, Context, Template, TemplateSyntaxError, VariableDoesNotExist |
39 | 40 |
from django.urls import reverse |
... | ... | |
1616 | 1617 |
return _('Exception') |
1617 | 1618 | |
1618 | 1619 |
def refresh_timeperiod_exceptions(self, data=None): |
1620 |
if 'uwsgi' in sys.modules: |
|
1621 |
from chrono.utils.spooler import refresh_exception_source |
|
1622 | ||
1623 |
tenant = getattr(connection, 'tenant', None) |
|
1624 |
transaction.on_commit( |
|
1625 |
lambda: refresh_exception_source.spool( |
|
1626 |
source_id=str(self.pk), domain=getattr(tenant, 'domain_url', None) |
|
1627 |
) |
|
1628 |
) |
|
1629 |
return |
|
1630 | ||
1619 | 1631 |
self.refresh_timeperiod_exceptions_from_ics(data=data) |
1620 | 1632 | |
1621 | 1633 |
def refresh_timeperiod_exceptions_from_ics(self, data=None, recurring_days=600): |
chrono/utils/spooler.py | ||
---|---|---|
14 | 14 |
# |
15 | 15 |
# You should have received a copy of the GNU Affero General Public License |
16 | 16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | ||
18 |
from django.db import connection |
|
19 | ||
20 |
from uwsgidecorators import spool |
|
21 | ||
22 |
from chrono.agendas.models import ICSError, TimePeriodExceptionSource |
|
23 | ||
24 | ||
25 |
def set_connection(domain): |
|
26 |
from hobo.multitenant.middleware import TenantMiddleware |
|
27 | ||
28 |
tenant = TenantMiddleware.get_tenant_by_hostname(domain) |
|
29 |
connection.set_tenant(tenant) |
|
30 | ||
31 | ||
32 |
@spool |
|
33 |
def refresh_exception_source(args): |
|
34 |
if args.get('domain'): |
|
35 |
# multitenant installation |
|
36 |
set_connection(args['domain']) |
|
37 | ||
38 |
try: |
|
39 |
source = TimePeriodExceptionSource.objects.get(pk=args['source_id']) |
|
40 |
except TimePeriodExceptionSource.DoesNotExist: |
|
41 |
return |
|
42 |
try: |
|
43 |
source.refresh_timeperiod_exceptions_from_ics() |
|
44 |
except ICSError: |
|
45 |
pass |
|
17 |
- |