Skip to content

Commit

Permalink
[Monitoring] timeout decorator to collect_metrics management command;…
Browse files Browse the repository at this point in the history
… avoids stucking on db connections
  • Loading branch information
afabiani committed May 17, 2019
1 parent faef956 commit c6356bf
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
#
#########################################################################
from __future__ import print_function
import logging

import pytz
import logging
import timeout_decorator

from datetime import datetime
from dateutil.tz import tzlocal

Expand All @@ -33,6 +36,8 @@
from geonode.contrib.monitoring.collector import CollectorAPI
from geonode.contrib.monitoring.utils import TypeChecks

LOCAL_TIMEOUT = 300

log = logging.getLogger(__name__)


Expand Down Expand Up @@ -64,6 +69,7 @@ def add_arguments(self, parser):
parser.add_argument('service', type=TypeChecks.service_type, nargs="?",
help=_("Collect data from this service only"))

@timeout_decorator.timeout(LOCAL_TIMEOUT)
def handle(self, *args, **options):
oservice = options['service']
if not oservice:
Expand Down Expand Up @@ -106,6 +112,7 @@ def handle(self, *args, **options):
notifications_check = now - interval
c.emit_notifications() #notifications_check)

@timeout_decorator.timeout(LOCAL_TIMEOUT)
def run_check(self, service, collector, since=None, until=None, force_check=None, format=None):
utc = pytz.utc
try:
Expand Down Expand Up @@ -137,4 +144,3 @@ def run_check(self, service, collector, since=None, until=None, force_check=None
return collector.process(service, data_in, last_check, until)
finally:
h.mark_as_checked()

0 comments on commit c6356bf

Please sign in to comment.