示例#1
0
    async def get_jobs(self, status: Optional[JobStatus] = None) -> List[JobInfo]:
        async with get_redis(self.redis_settings) as redis:
            job_ids = set(await redis.zrangebyscore(self.name))
            result_keys = await redis.keys(f'{result_key_prefix}*')
            job_ids |= {key[len(result_key_prefix):] for key in result_keys}

            if status:
                job_ids_tuple = tuple(job_ids)
                statuses = await asyncio.gather(*[self._get_job_status(job_id, redis) for job_id in job_ids_tuple])
                job_ids = {job_id for (job_id, job_status) in zip(job_ids_tuple, statuses) if job_status == status}

            jobs: List[JobInfo] = await asyncio.gather(*[self.get_job_by_id(job_id, redis) for job_id in job_ids])

        return jobs
示例#2
0
    async def get_stats(self) -> QueueStats:
        async with get_redis(self.redis_settings) as redis:
            job_ids = set(await redis.zrangebyscore(self.name))
            result_keys = await redis.keys(f'{result_key_prefix}*')
            job_ids |= {key[len(result_key_prefix):] for key in result_keys}

            statuses = await asyncio.gather(*[self._get_job_status(job_id, redis) for job_id in job_ids])

        return QueueStats(
            name=self.name,
            host=str(self.redis_settings.host),
            port=self.redis_settings.port,
            database=self.redis_settings.database,
            queued_jobs=len([status for status in statuses if status == JobStatus.queued]),
            complete_jobs=len([status for status in statuses if status == JobStatus.complete]),
            running_jobs=len([status for status in statuses if status == JobStatus.in_progress]),
            deferred_jobs=len([status for status in statuses if status == JobStatus.deferred]),
        )
示例#3
0
 async def get_job_by_id(self, job_id: str, redis: Optional[ArqRedis] = None) -> JobInfo:
     if redis is None:
         async with get_redis(self.redis_settings) as redis:
             return await self._get_job_by_id(job_id, redis)
     return await self._get_job_by_id(job_id, redis)
示例#4
0
async def redis() -> AsyncGenerator[ArqRedis, None]:
    async with get_redis(REDIS_SETTINGS) as redis:
        await redis.flushall()
        yield redis
示例#5
0
    async def _get_job_id() -> str:
        async with get_redis(settings.REDIS_SETTINGS) as redis:
            keys = await redis.keys(result_key_prefix + '*')

        return keys[0][len(result_key_prefix):]