Browse Source

Add --no-loop option to sendalerts management command.

Allow `sendalerts` to be run by an external scheduler, on a one-shot
basis, exiting after all alerts have been sent.
pull/117/head
Ronald Ip 8 years ago
parent
commit
7900a201c1
No known key found for this signature in database GPG Key ID: B74B616707867821
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