def _ids_by_seq(self, database): if self.seq == "0" or self.seq is None: return self.get_all_ids() consumer = Consumer(database) view_results = consumer.fetch(since=self.seq) if view_results: include_ids = set([res["id"] for res in view_results["results"]]) return include_ids.intersection(self.get_all_ids()) else: # sometimes this comes back empty. I think it might be a bug # in couchdbkit, but it's impossible to consistently reproduce. # For now, just assume this is fine. return set()
def handle(self, *args, **options): db = get_db() c = Consumer(db) # sync design docs to the target db # lots of source diving to figure out this magic new_dbs = [(app, global_config.database.uri) for app, _ in settings.COUCHDB_DATABASES] couchdbkit_handler = CouchdbkitHandler(new_dbs) for app, _ in new_dbs: try: couchdbkit_handler.sync(models.get_app(app)) except ImproperlyConfigured: # if django doesn't think this is an app it throws this error # this is probably fine pass # also sync couchapps sync_design_docs(global_config.database) def sync_if_necessary(line): try: change = Change(line) # don't bother with deleted or old documents if change.deleted or not change.is_current(db): return # get doc doc = get_db().get(change.id) # check if transforms, and if so, save to new domain/db transforms = global_config.get_transforms(doc) for transform in transforms: global_config.save(transform) # update the checkpoint, somewhat arbitrarily global domainsync_counter domainsync_counter = domainsync_counter + 1 if domainsync_counter % CHECKPOINT_FREQUENCY == 0: Checkpoint.set_checkpoint(CHECKPOINT_ID, change.seq) except Exception, e: logging.exception("problem in domain sync for line: %s\n%s" % (line, e))
def spool(): update_seq = cq.db.info()['update_seq'] c = Consumer(cq.db) c.wait(run_item, since=update_seq)