def handle(self, *args, **options):

        if options['all_time']:
            now = datetime.datetime.now()
            start = datetime.datetime(2017, 1, 1, 0, 0, 0)
            time_periods = create_full_time_periods(start, now, "q", {})
            all_periods = [(period['time_period']['fy'],
                            period['time_period']['q'])
                           for period in time_periods]
            for idx, val in enumerate(all_periods):
                fy = val[0]
                q = val[1]
                try:
                    logger.info(
                        'Running submission load for fy {}, quarter {}...'.
                        format(fy, q))
                    call_command('load_multiple_submissions', int(fy), int(q))
                except CommandError:
                    logger.info(
                        'Error reported using fy/q combination: {} {}'.format(
                            fy, q))
                    continue
        elif options['ids']:
            for idx in options['ids']:
                logger.info(
                    "Running submission load for submission id {}".format(idx))
                try:
                    call_command('load_submission', '--noclean',
                                 '--nosubawards', idx)
                except CommandError:
                    logger.info(
                        'Skipping submission ID {} due to CommandError (bad ID)'
                        .format(idx))
                    continue
 def run_for_all_fiscal_years(self):
     """Determine current FY+Q and run load_multiple_submissions from FY2017Q2 - current"""
     now = datetime.datetime.now()
     start = datetime.datetime(2017, 1, 1, 0, 0, 0)
     time_periods = create_full_time_periods(start, now, "q", {})
     all_periods = [(period["time_period"]["fy"], period["time_period"]["q"]) for period in time_periods]
     logger.info("Loading DABS Submissions from FY2017-Q2 to FY{}-{}".format(all_periods[-1][0], all_periods[-1][1]))
     for fiscal_year_and_quarters in all_periods:
         fy = int(fiscal_year_and_quarters[0])
         q = int(fiscal_year_and_quarters[1])
         start_msg = f"Running submission load for FY{fy}-Q{q}"
         logger.info(start_msg)
         logger.info("=" * len(start_msg))
         try:
             call_command("load_multiple_submissions", fy, q)
         except (CommandError, SystemExit, Exception):
             logger.exception(f"Submission(s) errors in FY{fy}-Q{q}. Continuing...")
             self.failed_state = True
    def handle(self, *args, **options):

        if options['all_time']:
            now = datetime.datetime.now()
            start = datetime.datetime(2017, 1, 1, 0, 0, 0)
            time_periods = create_full_time_periods(start, now, "q", {})
            all_periods = [(period['time_period']['fy'], period['time_period']['q']) for period in time_periods]
            for idx, val in enumerate(all_periods):
                fy = val[0]
                q = val[1]
                try:
                    logger.info('Running submission load for fy {}, quarter {}...'.format(fy, q))
                    call_command('load_multiple_submissions', int(fy), int(q))
                except CommandError:
                    logger.info('Error reported using fy/q combination: {} {}'.format(fy, q))
                    continue
        elif options['ids']:
            for idx in options['ids']:
                logger.info("Running submission load for submission id {}".format(idx))
                try:
                    call_command('load_submission', '--noclean', '--nosubawards', idx)
                except CommandError:
                    logger.info('Skipping submission ID {} due to CommandError (bad ID)'.format(idx))
                    continue