예제 #1
0
def close_opened_tasks():
    task_closer = TaskCloser()
    for stage_settings in settings.DATAJSONAR_STAGES.values():
        task_name = stage_settings.get('task')
        if task_name:
            task = import_string(task_name)
            task_closer.close_all_opened(task)
예제 #2
0
def pending_or_running_jobs_in_task_queue(task_model):
    for name, stage_settings in settings.DATAJSONAR_STAGES.items():
        stage_task_model = import_string(stage_settings['task'])
        if stage_task_model == task_model:
            return pending_or_running_jobs(stage_settings['queue'])

    raise ValueError('No hay stage que use el modelo {task_model}'.format(
        task_model=task_model))
예제 #3
0
 def get_running_task(self):
     if self.task:
         task_model = import_string(self.task)
     else:
         return None
     try:
         return task_model.objects\
             .filter(status=task_model.RUNNING).latest('created')
     except task_model.DoesNotExist:
         return None
예제 #4
0
 def test_close_all_is_called_with_task(self, task_closer):
     setattr(settings, 'DATAJSONAR_STAGES', {
         'Read Datajson (complete)': {
             'callable_str': 'django_datajsonar.tasks.schedule_full_read_task',
             'queue': 'indexing',
             'task': 'django_datajsonar.models.ReadDataJsonTask',
         }
     })
     close_opened_tasks()
     model = import_string('django_datajsonar.models.ReadDataJsonTask')
     task_closer().close_all_opened.assert_called_with(model)
예제 #5
0
    def clean(self):
        errors = {}
        try:
            method = import_string(self.callable_str)
            if not callable(method):
                msg = 'callable_str must be callable: {}'\
                    .format(self.callable_str)
                errors.update({'callable_str': ValidationError(msg)})

            if not hasattr(method, 'delay'):
                msg = 'method referenced is not an rq job ' \
                      '(has no "delay" attribute: {}'.format(self.callable_str)
                errors.update({'callable_str': msg})

        except (ImportError, ValueError):
            msg = 'Unable to import callable_str: {}'.format(self.callable_str)
            errors.update({'callable_str': ValidationError(msg)})

        if self.queue not in settings.RQ_QUEUES:
            msg = 'Queue is not defined in settings: {}'.format(self.queue)
            errors.update({'queue': ValidationError(msg)})

        if self.task:
            try:
                task_model = import_string(self.task)
                if not issubclass(task_model, AbstractTask):
                    msg = 'task must be an AbstractTask subclass: {}'\
                        .format(self.task)
                    errors.update({'task': ValidationError(msg)})
            except (ImportError, TypeError, ValueError):
                errors.update({
                    'task':
                    ValidationError('If present, task must be importable')
                })

        if self.next_stage and self.pk and self.next_stage.pk == self.pk:
            msg = 'next_stage must point to a different_stage: {}'.format(self)
            errors.update({'next_stage': ValidationError(msg)})

        if errors:
            raise ValidationError(errors)
예제 #6
0
 def test_report_generation_task_is_importable(self):
     self.assertIsNotNone(
         import_string(
             'monitoreo.apps.dashboard.models.ReportGenerationTask'))
예제 #7
0
 def test_validation_report_task_is_importable(self):
     self.assertIsNotNone(
         import_string(
             'monitoreo.apps.dashboard.models.ValidationReportTask'))
예제 #8
0
 def open_stage(self, node=None):
     job = import_string(self.callable_str)
     job.delay(node)
     self.status = Stage.ACTIVE
     self.save()