Browse Source

Merge pull request #117 from iphoting/sendalerts-no-loop

Add --no-loop option to sendalerts management command.
pull/118/head
Pēteris Caune 8 years ago
committed by GitHub
parent
commit
ec7fa1124f
1 changed files with 16 additions and 0 deletions
  1. +16
    -0
      hc/api/management/commands/sendalerts.py

+ 16
- 0
hc/api/management/commands/sendalerts.py View File

@ -26,6 +26,15 @@ class Command(BaseCommand):
help = 'Sends UP/DOWN email alerts' help = 'Sends UP/DOWN email alerts'
owned = Check.objects.filter(user__isnull=False) owned = Check.objects.filter(user__isnull=False)
def add_arguments(self, parser):
parser.add_argument(
'--no-loop',
action='store_false',
dest='loop',
default=True,
help='Do not keep running indefinitely in a 2 second wait loop',
)
def handle_one(self): def handle_one(self):
""" Process a single check. """ """ Process a single check. """
@ -62,6 +71,13 @@ class Command(BaseCommand):
return False return False
def handle(self, *args, **options): def handle(self, *args, **options):
if not options["loop"]:
x = 0
while self.handle_one():
# returns True when there are more alerts to send.
x += 1
return "Sent %d alert(s)" % x
self.stdout.write("sendalerts is now running") self.stdout.write("sendalerts is now running")
ticks = 0 ticks = 0


Loading…
Cancel
Save