示例#1
0
    def test_dependency_cycle(self):

        for table_slug in ALL_TABLES:
            self.assertFalse(
                _has_cycles(table_slug,
                            get_cls_by_slug(table_slug).dependencies()),
                '{} has a dependency cycle'.format(table_slug))
示例#2
0
    def handle(self, slug, batch_id, **options):
        try:
            batch = Batch.objects.get(pk=batch_id)
        except Batch.DoesNotExist:
            raise CommandError('Invalid batch ID: {}'.format(batch_id))

        try:
            model = get_cls_by_slug(slug)
        except KeyError:
            raise CommandError('{} is not a valid slug. \n\n {}'.format(
                slug, USAGE))

        commit_record = CommitRecord(
            slug=slug,
            batch=batch,
            verified=False,
        )
        try:
            commit_record.verified = model.commit(batch)
        except Exception as e:
            commit_record.error = e
            commit_record.success = False
            raise
        else:
            commit_record.success = True
        finally:
            commit_record.completed_on = datetime.utcnow()
            commit_record.save()
示例#3
0
    def handle(self, slug, **options):
        start = options.get('start')
        end = options.get('end')

        try:
            model = get_cls_by_slug(slug)
        except KeyError:
            raise CommandError('{} is not a valid slug. \n\n {}'.format(
                slug, USAGE))
        model.commit(start, end)
示例#4
0
def _has_cycles(table_slug, deps):
    if table_slug in deps:
        return True

    for dep_slug in deps:
        warehouse_cls = get_cls_by_slug(dep_slug)
        if _has_cycles(table_slug, warehouse_cls.dependencies()):
            return True

    return False
示例#5
0
    def _table_context(cls, start_datetime, end_datetime):
        '''
        Get a dict of slugs to table name mapping
        :returns: Dict of slug to table_name
        {
            <slug>: <table_name>,
            ...
        }
        '''
        from corehq.warehouse.models import get_cls_by_slug

        context = {cls.slug: cls._meta.db_table}
        for dep in cls.dependencies():
            dep_cls = get_cls_by_slug(dep)
            context[dep] = dep_cls._meta.db_table
        context['start_datetime'] = start_datetime
        context['end_datetime'] = start_datetime
        return context
示例#6
0
    def _table_context(cls, batch):
        '''
        Get a dict of slugs to table name mapping
        :returns: Dict of slug to table_name
        {
            <slug>: <table_name>,
            ...
        }
        '''
        from corehq.warehouse.models import get_cls_by_slug

        context = {cls.slug: cls._meta.db_table}
        for dep in cls.dependencies():
            dep_cls = get_cls_by_slug(dep)
            context[dep] = dep_cls._meta.db_table
        context['start_datetime'] = batch.start_datetime.isoformat()
        context['end_datetime'] = batch.end_datetime.isoformat()
        context['batch_id'] = batch.id
        context.update(cls.additional_sql_context())
        return context
示例#7
0
文件: etl.py 项目: ye-man/commcare-hq
    def _table_context(cls, batch):
        '''
        Get a dict of slugs to table name mapping
        :returns: Dict of slug to table_name
        {
            <slug>: <table_name>,
            ...
        }
        '''
        from corehq.warehouse.models import get_cls_by_slug

        context = {cls.slug: cls._meta.db_table}
        for dep in cls.dependencies():
            dep_cls = get_cls_by_slug(dep)
            context[dep] = dep_cls._meta.db_table
        context['start_datetime'] = batch.start_datetime.isoformat()
        context['end_datetime'] = batch.end_datetime.isoformat()
        context['batch_id'] = batch.id
        context.update(cls.additional_sql_context())
        return context
示例#8
0
 def handle(self, **options):
     for slug in STAGING_TABLES:
         model = get_cls_by_slug(slug)
         model.clear_records()
 def handle(self, **options):
     for slug in STAGING_TABLES:
         model = get_cls_by_slug(slug)
         model.clear_records()