예제 #1
0
 def _update_row(self, obj, table):
     pk = obj.primary_key
     uuid = pk.id
     cloud = pk.cloud
     type_name = _type_name(obj.get_class())
     sql_statement = \
         'INSERT OR REPLACE INTO {table} ' \
         'VALUES (:uuid, :cloud, :type_name, :data)'.format(table=table)
     self.tx.execute(sql_statement,
                     uuid=uuid, cloud=cloud, type_name=type_name,
                     data=local_db.Json(obj.dump(table)))
     obj.clear_dirty(table)
     assert not obj.is_dirty(table)
예제 #2
0
def execute_stage(class_name, config, force=False):
    """
    Execute stage specified by `class_name` argument.
    :param class_name: fully qualified stage class name
    :param config: config.Configuration instance
    """

    # Create stage object
    cls = importutils.import_class(class_name)
    assert issubclass(cls, Stage)
    stage = cls(config)

    # Execute dependency stages
    for dependency in stage.dependencies:
        execute_stage(dependency, config)

    # Check if there is data from this stage in local DB
    new_signature = stage.signature()
    old_signature = None
    need_invalidate = False
    need_execute = False
    with local_db.Transaction() as tx:
        row = tx.query_one('SELECT signature FROM stages WHERE stage=:stage',
                           stage=class_name)
        if row is None:
            need_execute = True
        else:
            old_signature = row['signature'].data
            need_invalidate = (old_signature != new_signature)

    # Run invalidate and execute if needed
    with local_db.Transaction() as tx:
        if need_invalidate or force:
            stage.invalidate(old_signature, new_signature, force=force)
            tx.execute('DELETE FROM stages WHERE stage=:stage',
                       stage=class_name)
            need_execute = True
        if need_execute:
            stage.execute()
            tx.execute('INSERT INTO stages VALUES (:stage, :signature)',
                       stage=class_name,
                       signature=local_db.Json(new_signature))
            LOG.info('Stage %s executed successfully', class_name)
        else:
            LOG.info('Skipping stage %s', class_name)