Commit e700d76f authored by guglielmo's avatar guglielmo

notify command embedded into content_verify: now the --notify option

allows to send notifications at the end of the content_verify task
parent 1a33d60e
import difflib
import datetime
from django.core import management
from taskmanager.logging_utils import LoggingBaseCommand
from project.webapp.models import Content
......@@ -12,11 +13,11 @@ class Command(LoggingBaseCommand):
parser.add_argument('id', nargs='*', type=int)
parser.add_argument(
'--dryrun',
'--dry-run',
action='store_true',
dest='dryrun',
default=False,
help='Execute a dry run: no db is written.',
help='Execute a dry run: no db is written, no notification sent.',
)
parser.add_argument(
'--content',
......@@ -34,7 +35,6 @@ class Command(LoggingBaseCommand):
)
parser.add_argument(
'--offset',
action='store',
type=int,
dest='offset',
default=0,
......@@ -42,12 +42,24 @@ class Command(LoggingBaseCommand):
)
parser.add_argument(
'--limit',
action='store',
type=int,
dest='limit',
default=0,
help='Force offset <> 0',
)
parser.add_argument(
'--notify',
action='store_true',
dest='notify',
default=False,
help='Notify changes to registered recipients or channels',
)
parser.add_argument(
'--notification-method',
dest='notification_method',
default='slack',
help='What method to use for notification: slack|email|both',
)
def handle(self, *args, **options):
self.setup_logger(__name__, formatter_key="simple", **options)
......@@ -86,7 +98,7 @@ class Command(LoggingBaseCommand):
cnt + 1, len(contents), err_msg, content.title, content.id
))
else:
print(
self.logger.info(
"{0}/{1} - {2} (id: {4}) - {3}".format(
cnt + 1, len(contents), content.title,
content.get_verification_status_display().upper(),
......@@ -100,3 +112,11 @@ class Command(LoggingBaseCommand):
stored = content.meat.splitlines(1)
diff = difflib.ndiff(live, stored)
self.logger.info("".join(diff))
if options['notify'] and not options['dryrun']:
verbosity = int(options.get("verbosity", 1))
management.call_command(
'notify',
verbosity=verbosity,
notification_method=options['notification_method'],
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment