Exemplo n.º 1
0
 def set_next_execution(self):
     """
     Set self.next_execution to the next time the import is going to be run. If run_immediately
     is set, time is set to now()
     """
     debug_enter(who_am_i(), who_is_parent(),
                 getframeinfo(currentframe()).lineno)
     time_adds = {
         self.EVERY_TWO_MINUTES: timedelta(seconds=120),  # used for testing
         self.HOURLY: timedelta(hours=1),
         self.EVERY_SIX_HOURS: timedelta(hours=6),
         self.DAILY: timedelta(days=1),
         self.EVERY_THREE_DAYS: timedelta(days=3),
         self.WEEKLY: timedelta(weeks=1),
         self.BI_WEEKLY: timedelta(weeks=2),
         self.EVERY_FOUR_WEEKS: timedelta(weeks=4),
     }
     if self.frequency:
         if not self.next_execution:
             self.next_execution = datetime.now() + time_adds[
                 self.frequency]
         else:
             self.next_execution += time_adds[self.frequency]
     else:
         self.next_execution = None
     self.save()
     debug_exit(who_am_i(), getframeinfo(currentframe()).lineno)
Exemplo n.º 2
0
    def check_execution(self):
        """
        Checks if we should run a job on this import. This is true if either:
            1) we find a job object with pending status, in that case this is a manual run initiated
               in the admin
            2) if no job is present we check if it's time for a scheduled execution of the import
        :param job: an IatiImportJob object
        :return:
        """
        debug_enter(who_am_i(), who_is_parent(),
                    getframeinfo(currentframe()).lineno)

        from .iati_import_log import IatiImportLog

        if not self.enabled:
            return
        job_model = self.job_model()
        try:
            job = job_model.objects.get(iati_import=self,
                                        status=LOG_ENTRY_TYPE.STATUS_PENDING)
        except job_model.DoesNotExist:
            job = None
        except job_model.MultipleObjectsReturned:
            for job in job_model.objects.filter(
                    iati_import=self, status=LOG_ENTRY_TYPE.STATUS_PENDING):
                IatiImportLog.objects.create(
                    iati_import_job=job,
                    text=
                    "Fatal error executing import. Multiple pending jobs found.",
                    created_at=datetime.now())
            return
        if self.run_immediately or self.it_is_time_to_execute():
            self.execute_import(job)
Exemplo n.º 3
0
    def check_execution(self):
        """
        Checks if we should run a job on this import. This is true if either:
            1) we find a job object with pending status, in that case this is a manual run initiated
               in the admin
            2) if no job is present we check if it's time for a scheduled execution of the import
        :param job: an IatiImportJob object
        :return:
        """
        debug_enter(who_am_i(), who_is_parent(), getframeinfo(currentframe()).lineno)

        from .iati_import_log import IatiImportLog

        if not self.enabled:
            return
        job_model = self.job_model()
        try:
            job = job_model.objects.get(iati_import=self, status=LOG_ENTRY_TYPE.STATUS_PENDING)
        except job_model.DoesNotExist:
            job = None
        except job_model.MultipleObjectsReturned:
            for job in job_model.objects.filter(
                    iati_import=self, status=LOG_ENTRY_TYPE.STATUS_PENDING):
                IatiImportLog.objects.create(
                    iati_import_job=job,
                    text="Fatal error executing import. Multiple pending jobs found.",
                    created_at=datetime.now()
                )
            return
        if self.run_immediately or self.it_is_time_to_execute():
            self.execute_import(job)
Exemplo n.º 4
0
 def set_next_execution(self):
     """
     Set self.next_execution to the next time the import is going to be run. If run_immediately
     is set, time is set to now()
     """
     debug_enter(who_am_i(), who_is_parent(), getframeinfo(currentframe()).lineno)
     time_adds = {
         self.EVERY_TWO_MINUTES: timedelta(seconds=120), # used for testing
         self.HOURLY: timedelta(hours=1),
         self.EVERY_SIX_HOURS: timedelta(hours=6),
         self.DAILY: timedelta(days=1),
         self.EVERY_THREE_DAYS: timedelta(days=3),
         self.WEEKLY: timedelta(weeks=1),
         self.BI_WEEKLY: timedelta(weeks=2),
         self.EVERY_FOUR_WEEKS: timedelta(weeks=4),
     }
     if self.frequency:
         if not self.next_execution:
             self.next_execution = datetime.now() + time_adds[self.frequency]
         else:
             self.next_execution += time_adds[self.frequency]
     else:
         self.next_execution = None
     self.save()
     debug_exit(who_am_i(), getframeinfo(currentframe()).lineno)
Exemplo n.º 5
0
 def test_inspection_definitions(self):
     """
     Tests for inspecting definitions.
     """
     this_definition = who_am_i()
     parent_definition = who_is_parent()
     self.assertEqual(this_definition, "test_inspection_definitions")
     self.assertEqual(parent_definition, "_callTestMethod")
Exemplo n.º 6
0
 def test_inspection_definitions(self):
     """
     Tests for inspecting definitions.
     """
     this_definition = who_am_i()
     parent_definition = who_is_parent()
     self.assertEqual(this_definition, "test_inspection_definitions")
     self.assertEqual(parent_definition, "run")
Exemplo n.º 7
0
 def it_is_time_to_execute(self):
     debug_enter(who_am_i(), who_is_parent(),
                 getframeinfo(currentframe()).lineno)
     return self.enabled and self.next_execution and self.next_execution < datetime.now(
     )
Exemplo n.º 8
0
 def it_is_time_to_execute(self):
     debug_enter(who_am_i(), who_is_parent(), getframeinfo(currentframe()).lineno)
     return self.enabled and self.next_execution and self.next_execution < datetime.now()