Beispiel #1
0
 def handle_result(self, instance, affected_rows, step_number, timer, user_id, _type):
     user = self.get_user(user_id)
     instance.execute_time = timer
     instance.affected_rows = affected_rows
     self.replace_remark(instance, _type, user)
     self.handle_workflow(2, 1, step_number, instance)
     self.save_instance(instance)
     RedisLock.delete_lock(instance.id)
     self.mail(instance, _type, user, self.name_mail_inception)
Beispiel #2
0
    async def launch_shards(self):
        log.info("Waiting to acquire a SHARD lock.")
        while not self.is_closed():
            tried = []
            for i in range(0, self.config.shard_count,
                           self.config.shards_per_pod):
                lock = RedisLock(self.redis,
                                 key="%s_%d" % (self.config.identifier, i),
                                 timeout=10,
                                 wait_timeout=0)
                if await lock.acquire():
                    log.info("Acquired the SHARD lock %d" % i)
                    self.shard_ids = list(
                        range(i, i + self.config.shards_per_pod))
                    self.loop.create_task(self._keep_shard_lock(lock))
                    return await super().launch_shards()

                else:
                    tried.append(i)

                await asyncio.sleep(0)  # Suspend

            log.info("Tried SHARD Locks (%s) with no success." %
                     ", ".join([str(j) for j in tried]))

            await asyncio.sleep(10)
Beispiel #3
0
 async def launch_shard(self, gateway, shard_id):
     log.info("Waiting to acquire the IDENTIFY lock.")
     async with RedisLock(
             self.redis,
             key="%s_identify" % self.config.identifier,
             timeout=200,  # More than the connect timeout
             wait_timeout=None):
         log.info("Shard ID %s has acquired the IDENTIFY lock." % shard_id)
         return await super().launch_shard(gateway, shard_id)
Beispiel #4
0
 def check_lock(self, instance):
     if not RedisLock.locked(instance.id):
         raise ParseError(self.task_locked.format(instance.id))