From 459b181d51c2c7b2b669998cd7d1786e3c2ce4d4 Mon Sep 17 00:00:00 2001 From: Bryan Wilson Date: Mon, 14 Jun 2021 13:47:05 -0700 Subject: [PATCH] pend deprecation populate_figures_metrics, replace functionality pass --mau usage to new run_figures_mau_metrics pass other usage to backfill_figures_daily_metrics (with start and end date of single date passed ) --- .../commands/populate_figures_metrics.py | 80 +++++++++++++++++++ .../commands/run_figures_mau_metrics.py | 36 +++++++++ 2 files changed, 116 insertions(+) create mode 100644 figures/management/commands/populate_figures_metrics.py create mode 100644 figures/management/commands/run_figures_mau_metrics.py diff --git a/figures/management/commands/populate_figures_metrics.py b/figures/management/commands/populate_figures_metrics.py new file mode 100644 index 00000000..8f25ed02 --- /dev/null +++ b/figures/management/commands/populate_figures_metrics.py @@ -0,0 +1,80 @@ +""" +Deprecated: +Please call instead backfill_figures_daily_metrics. + +Management command to manually populate course metrics + +see the model ``edx_figures.models.CourseDailyMetrics`` +""" + +from __future__ import print_function + +from __future__ import absolute_import +from textwrap import dedent +import warnings + +from django.core.management import call_command +from django.core.management.base import BaseCommand + + +class Command(BaseCommand): + '''Populate Figures metrics models + ''' + help = dedent(__doc__).strip() + + def add_arguments(self, parser): + ''' + ''' + + parser.add_argument('--date', + help='date for which we are retrieving data in yyyy-mm-dd format') + parser.add_argument('--no-delay', + action='store_true', + default=False, + help='Disable the celery "delay" directive') + parser.add_argument('--force-update', + action='store_true', + default=False, + help='Overwrite metrics records if they exist for the given date') + parser.add_argument('--experimental', + action='store_true', + default=False, + help=('Run with Celery workflows (Warning: This is still under' + + ' development and likely to get stuck/hung jobs')) + parser.add_argument('--mau', + action='store_true', + default=False, + help='Run just the MAU pipeline') + + def handle(self, *args, **options): + ''' + Pending deprecation. Passes handling off to new commands. + + The 'mau' conditional check in this method is a quick hack to run the + MAU task from this command. What we probably want is a 'figures_cli' + command with subcommands. + ''' + warnings.warn( + "populate_figures_metrics is pending deprecation and will be removed in " + "Figures 1.0. Please use backfill_figures_daily_metrics, instead; or, " + "if you were calling with --mau option, use populate_figures_mau_metrics.", + PendingDeprecationWarning + ) + print('populating Figures metrics...') + + if options['mau']: + call_command('run_figures_mau_metrics', no_delay=options['no_delay']) + else: + call_command( + 'backfill_figures_daily_metrics', + no_delay=options['no_delay'], + date_start=options['date'], + date_end=options['date'], + overwrite=options['force_update'], + experimental=options['experimental'] + ) + + # TODO: improve this message to say 'today' when options['date'] is None + print('Management command populate_figures_metrics complete. date_for: {}'.format( + options['date'])) + print('Done.') diff --git a/figures/management/commands/run_figures_mau_metrics.py b/figures/management/commands/run_figures_mau_metrics.py new file mode 100644 index 00000000..f7d7d5a3 --- /dev/null +++ b/figures/management/commands/run_figures_mau_metrics.py @@ -0,0 +1,36 @@ +"""Figures management command to run course MAU metrics for all courses, all Sites. +""" + +from __future__ import print_function + +from __future__ import absolute_import + +from textwrap import dedent + +from django.core.management.base import BaseCommand + +from figures.tasks import ( + populate_all_mau +) + + +class Command(BaseCommand): + """Task runner to kick off Figures celery tasks + """ + help = dedent(__doc__).strip() + + def add_arguments(self, parser): + parser.add_argument('--no-delay', + action='store_true', + default=False, + help='Disable the celery "delay" directive') + + def handle(self, *args, **options): + print('Starting Figures MAU metrics for all Sites...') + + if options['no_delay']: + populate_all_mau() + else: + populate_all_mau.delay() + + print('Done.')