예제 #1
0
def get_all_expired_jobs(now=None, conn=None):
    """Retrieve all expired jobs
    Kwargs:
        now (float): The epoch time to compare against,
            during the retrieval process.
            Default: (Is to use the epoch time of right now)

    Basic Usage:
        >>> from vFense.queue._db import get_all_expired_jobs
        >>> now = 1396780822.0
        >>> get_all_expired_jobs(now)

    Returns:
        List of dictionairies
        [
            {
                "agent_queue_ttl": 1396778416, 
                "plugin": "rv", 
                "order_id": 1, 
                "server_queue_ttl": 1396777816, 
                "agent_id": "d4119b36-fe3c-4973-84c7-e8e3d72a3e02", 
                "created_time": 1396777216, 
                "operation_id": "b95837d9-5df7-4ab0-9449-a7be196a2b12", 
                "operation": "updatesapplications", 
                "id": "f9817e07-6877-4857-aef3-e80f57022ac8", 
                "expire_minutes": 10, 
                "customer_name": "default"
            }
        ]
    """
    expired_jobs = []
    try:
        if not now:
            expired_jobs = list(
                r
                .table(QueueCollections.Agent)
                .filter(
                    lambda x: x[AgentQueueKey.ServerQueueTTL] <= r.now()
                )
                .run(conn)
            )

        else:
            expired_jobs = list(
                r
                .table(QueueCollections.Agent)
                .filter(
                    lambda x:
                        x[AgentQueueKey.ServerQueueTTL].to_epoch_time() <= now
                )
                .run(conn)
            )

    except Exception as e:
        logger.exception(e)

    return(expired_jobs)
예제 #2
0
def delete_all_expired_jobs(now=None, conn=None):
    """Delete all expired jobs in the queue
        DO NOT CALL DIRECTLY
    Kwargs:
        now (float): The epoch time to compare against,
            during the deletion process.
            Default: (Is to use the epoch time of right now)

    Basic Usage:
        >>> from vFense.queue._db import delete_all_expired_jobs
        >>> now = 1396780822.0
        >>> delete_all_expired_jobs(now)

    Returns:
        Tuple (status_code, count, error, generated ids)
        >>> (2001, 1, None, [])
    """
    try:
        if not now:
            data = (
                r
                .table(QueueCollections.Agent)
                .filter(
                    lambda x: x[AgentQueueKey.ServerQueueTTL] <= r.now()
                )
                .delete()
                .run(conn)
            )

        else:
            data = (
                r
                .table(QueueCollections.Agent)
                .filter(
                    lambda x:
                        x[AgentQueueKey.ServerQueueTTL].to_epoch_time() <= now
                )
                .delete()
                .run(conn)
            )

    except Exception as e:
        logger.exception(e)

    return(data)
예제 #3
0
파일: _db.py 프로젝트: ttysteale/vFense
def delete_all_expired_jobs(now=None, conn=None):
    """Delete all expired jobs in the queue
        DO NOT CALL DIRECTLY
    Kwargs:
        now (float): The epoch time to compare against,
            during the deletion process.
            Default: (Is to use the epoch time of right now)

    Basic Usage:
        >>> from vFense.queue._db import delete_all_expired_jobs
        >>> now = 1396780822.0
        >>> delete_all_expired_jobs(now)

    Returns:
        Tuple (status_code, count, error, generated ids)
        >>> (2001, 1, None, [])
    """
    try:
        if not now:
            data = (
                r.table(QueueCollections.Agent)
                .filter(lambda x: x[AgentQueueKey.ServerQueueTTL] <= r.now())
                .delete()
                .run(conn)
            )

        else:
            data = (
                r.table(QueueCollections.Agent)
                .filter(lambda x: x[AgentQueueKey.ServerQueueTTL].to_epoch_time() <= now)
                .delete()
                .run(conn)
            )

    except Exception as e:
        logger.exception(e)

    return data
예제 #4
0
파일: _db.py 프로젝트: ttysteale/vFense
def get_all_expired_jobs(now=None, conn=None):
    """Retrieve all expired jobs
    Kwargs:
        now (float): The epoch time to compare against,
            during the retrieval process.
            Default: (Is to use the epoch time of right now)

    Basic Usage:
        >>> from vFense.queue._db import get_all_expired_jobs
        >>> now = 1396780822.0
        >>> get_all_expired_jobs(now)

    Returns:
        List of dictionairies
        [
            {
                "agent_queue_ttl": 1396778416, 
                "plugin": "rv", 
                "order_id": 1, 
                "server_queue_ttl": 1396777816, 
                "agent_id": "d4119b36-fe3c-4973-84c7-e8e3d72a3e02", 
                "created_time": 1396777216, 
                "operation_id": "b95837d9-5df7-4ab0-9449-a7be196a2b12", 
                "operation": "updatesapplications", 
                "id": "f9817e07-6877-4857-aef3-e80f57022ac8", 
                "expire_minutes": 10, 
                "customer_name": "default"
            }
        ]
    """
    expired_jobs = []
    try:
        if not now:
            expired_jobs = list(
                r.table(QueueCollections.Agent).filter(lambda x: x[AgentQueueKey.ServerQueueTTL] <= r.now()).run(conn)
            )

        else:
            expired_jobs = list(
                r.table(QueueCollections.Agent)
                .filter(lambda x: x[AgentQueueKey.ServerQueueTTL].to_epoch_time() <= now)
                .run(conn)
            )

    except Exception as e:
        logger.exception(e)

    return expired_jobs