def flush_heartbeat_queue(queue):
    with queue as db:
        for task in queue:
            if task is None:
                break

            _L.info('Got heartbeat {}: {}'.format(task.id, task.data))
            id, kind = task.data.get('worker_id'), task.data.get('worker_kind')
            
            db.execute('''DELETE FROM heartbeats
                          WHERE worker_id = %s
                            AND ((worker_kind IS NULL AND %s IS NULL)
                                 OR worker_kind = %s)''',
                       (id, kind, kind))
            
            db.execute('''INSERT INTO heartbeats (worker_id, worker_kind, datetime)
                          VALUES (%s, %s, NOW())''',
                       (id, kind))
Store to entity, deleting dynamic properties that no longer exist.
dataset/ETHPy150Open openaddresses/machine/openaddr/ci/__init__.py/flush_heartbeat_queue--crossover with--dataset/ETHPy150Open CollabQ/CollabQ/.google_appengine/google/appengine/ext/db/__init__.py/Expando._to_entity