soonq/broker.py
def enqueue(self, item, queue_name):
        """Enqueue the given item in the queue with the given name."""
        con = sqlite3.connect(str(DB_PATH))
        with con:
            c = con.execute(
                f"""
                SELECT position
                FROM {QUEUE_TABLENAME}
                ORDER BY position DESC
                """
            )
            max_position = c.fetchone()  # Returns a tuple.
            new_position = max_position[0] + 1 if max_position else 0
            # Serialize objects to be stored as BLOB.
            item["args"] = pickle.dumps(
                item["args"],
                protocol=pickle.HIGHEST_PROTOCOL,
            )
            item["kwargs"] = pickle.dumps(
                item["kwargs"],
                protocol=pickle.HIGHEST_PROTOCOL,
            )
            con.execute(
                f"""
                INSERT INTO {QUEUE_TABLENAME} (
                    task_id,
                    queue_name,
                    position,
                    published,
                    args,
                    kwargs
                )
                VALUES (?, ?, ?, ?, ?, ?)
                """,
                (
                    item["task_id"],
                    queue_name,
                    new_position,
                    dt.datetime.now(),
                    item["args"],
                    item["kwargs"],
                ),
            )
        con.close()
Enqueue the given item in the queue with the given name.
Enqueue the given item in the queue with the given name.
Enqueue the given item in the queue with the given name .
def enqueue(self, item, queue_name):
        con = sqlite3.connect(str(DB_PATH))
        with con:
            c = con.execute(
                f"""
                SELECT position
                FROM {QUEUE_TABLENAME}
                ORDER BY position DESC
                """
            )
            max_position = c.fetchone()  
            new_position = max_position[0] + 1 if max_position else 0
            item["args"] = pickle.dumps(
                item["args"],
                protocol=pickle.HIGHEST_PROTOCOL,
            )
            item["kwargs"] = pickle.dumps(
                item["kwargs"],
                protocol=pickle.HIGHEST_PROTOCOL,
            )
            con.execute(
                f"""
                INSERT INTO {QUEUE_TABLENAME} (
                    task_id,
                    queue_name,
                    position,
                    published,
                    args,
                    kwargs
                )
                VALUES (?, ?, ?, ?, ?, ?)
                """,
                (
                    item["task_id"],
                    queue_name,
                    new_position,
                    dt.datetime.now(),
                    item["args"],
                    item["kwargs"],
                ),
            )
        con.close()
def enqueue ( self , item , queue_name ) : con = sqlite3 . connect ( str ( DB_PATH ) ) with con : c = con . execute ( f"""
                SELECT position
                FROM {QUEUE_TABLENAME}
                ORDER BY position DESC
                """ ) max_position = c . fetchone ( ) new_position = max_position [ 0 ] + 1 if max_position else 0 item [ "args" ] = pickle . dumps ( item [ "args" ] , protocol = pickle . HIGHEST_PROTOCOL , ) item [ "kwargs" ] = pickle . dumps ( item [ "kwargs" ] , protocol = pickle . HIGHEST_PROTOCOL , ) con . execute ( f"""
                INSERT INTO {QUEUE_TABLENAME} (
                    task_id,
                    queue_name,
                    position,
                    published,
                    args,
                    kwargs
                )
                VALUES (?, ?, ?, ?, ?, ?)
                """ , ( item [ "task_id" ] , queue_name , new_position , dt . datetime . now ( ) , item [ "args" ] , item [ "kwargs" ] , ) , ) con . close ( )
Enqueue the given item in the queue with the given name.
Enqueue the given item in the queue with the given name .
"""Enqueue the given item in the queue with the given name.""" # Returns a tuple. # Serialize objects to be stored as BLOB.
self
item
queue_name