Example #1
0
def clean_queue(msg: str) -> str:
    db = SessionLocal()
    print("In clear_queue()")
    counter = 0
    timeout = datetime.datetime.utcnow() - datetime.timedelta(minutes=15)
    old_queue = db.query(Queue).filter(Queue.pending == True).\
        filter(Queue.arrival_time <= timeout).filter(Queue.in_progress == False)
    for row in old_queue:
        print(f"Timing out queue entry {row.uuid}")
        stat_queue = Statistics(uuid=row.uuid,
                                arrival_time=row.arrival_time,
                                dequeued_at=row.dequeued_at,
                                deleted_at=datetime.datetime.utcnow(),
                                purged=True)
        db.add(stat_queue)
        counter += 1
        db.delete(row)
    timeout = datetime.datetime.utcnow() - datetime.timedelta(minutes=60 * 24)
    very_old_queue = db.query(Queue).filter(Queue.arrival_time <= timeout)
    for row in very_old_queue:
        print(f"Timing out queue entry {row.uuid}")
        stat_queue = Statistics(uuid=row.uuid,
                                arrival_time=row.arrival_time,
                                dequeued_at=row.dequeued_at,
                                deleted_at=datetime.datetime.utcnow(),
                                purged=True)
        db.add(stat_queue)
        counter += 1
        db.delete(row)
    db.commit()
    return f"Queue cleaned, {counter} entries removed."
Example #2
0
def remove_queue(*, db: Session = Depends(deps.get_db), uuid: str) -> Any:
    """
    Delete from queue by UUID
    """
    try:

        row = db.query(Queue).filter(
            func.lower(Queue.uuid) == uuid.lower()).one()
        if not row:
            raise HTTPException(status_code=404, detail="UUID not found")
        client = db.query(Client).filter(Client.id == row.client.id).one()
        stat_queue = Statistics(uuid=row.uuid,
                                arrival_time=row.arrival_time,
                                dequeued_at=row.dequeued_at,
                                deleted_at=datetime.datetime.utcnow(),
                                purged=False)
        db.add(stat_queue)
        db.commit()
        crud.client.remove(db=db, id=client.id)
        crud.queue.remove(db=db, id=row.id)
        old_queue = db.query(Queue).filter(
            Queue.arrival_time <= (datetime.datetime.utcnow() -
                                   datetime.timedelta(hours=24)))
        if old_queue.count() >= 1:
            celery_app.send_task("app.worker.clean_queue",
                                 args=["Cleanup started by stale cases."])
        return {'status': f'Success!'}
    except NoResultFound:
        raise HTTPException(status_code=404, detail="UUID not found")
    except MultipleResultsFound:
        raise HTTPException(status_code=500,
                            detail="More than one UUID was found! "
                            "This should never happen.")
Example #3
0
def lol():
    counter = Statistics.query.first()
    if counter is None:
        counter = Statistics(rickroll_counter=0)
        db.session.add(counter)
    counter.rickroll_counter += 1
    db.session.commit()
    return redirect("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
Example #4
0
def before_request():
    if request.path != '/notifications':
        s = Statistics.query.filter_by(id=1).first()
        if s == None:
            post = Statistics(total_visit_number=1)
            g.total_visit_number = 1
            db.session.add(post)
        else:
            s.total_visit_number += 1
            g.total_visit_number = s.total_visit_number
        db.session.commit()

        custom_print(s.total_visit_number)
    if current_user.is_authenticated:
        current_user.last_seen = datetime.utcnow()
        db.session.commit()
        g.search_form = SearchForm()
    g.locale = str(get_locale())
Example #5
0
def credential(item: ValidateAuthorizableAttributeInfoInput = Body(
    ...,
    example={
        "authorizable_attribute_id":
        "Authorizable Attribute Unique Identifier",
        "blind_sign_request": {
            "request": {
                "pi_s": {
                    "c":
                    "9fbe906553d2d15959094a42e3863f71f90634a15172d30cf5d5cda555836c1a",
                    "rk":
                    "0cff3b2b8b9e28c63f4902303e4d6ba2c6aac096543098b87ff8fa817be22d61",
                    "rm":
                    "2698c1e293341ca1d28782a34ef74814249b516431aab963fcb31c19a22f41a0",
                    "rr":
                    "32c0c70c0f6a65b58ab8f23742e695743c4e3672f1ca4c92fd30545aab4e5b45",
                },
                "zenroom": "0.8.1",
                "schema": "lambda",
                "c": {
                    "a":
                    "040b7c7b31f9c81daf812d87999a9f53e5a2e6c9b1a2a3df42db155066d1c22674acc579798d6d544427b23dd77b379b9e3d4556806f9b2bdd940aba61495f9d392011a639f8d75f1f0e68906f0e1a0d61eda3a2a621e4f173b35a6d00a36dd51d",
                    "b":
                    "040acd0a9a4b39409c17ea2cbf73354c9f6bb410e126c25865003dcc356bcec31a81c8696e6dbe4011962f98d316f475a01d76d8b95ddd99dc97ef67119f82ccd6bd5711e5c63af48414a945604d620ac4dbf357cd2b250fc787e98ac754b66805",
                },
                "public":
                "0428f6fd3e9cb1b2a95acce09cc928097f8fe64802b30511d3b18e5fa0f1c50a902c0090b74942070f0fe5e2b84124590b0a45f37507a33ead6cd2f3650f606aea28dbe3506cd0011bddf7657de5d0211582803ea91e67103310d2f2b5c97509d3",
                "cm":
                "043a0ddff5a122cd75a4bda44bd220b13d0d05d2b2e751d02a30b92ca148fd5e56fdf7530bf8c0f1071dab4ccb504b49f522f54047cd15fc4b3a5b34a42c702a8e6e4d396d3e60eb88f309530389c903f1d9f0354f44b1de4d4dccdb28705e677f",
                "encoding": "hex",
                "curve": "bls383",
            }
        },
        "values": [
            {
                "name": "zip_code",
                "value": "08001"
            },
            {
                "name": "email",
                "value": "*****@*****.**"
            },
        ],
        "optional_values": [{
            "name": "age",
            "value": "18-25"
        }],
    },
)):
    aa = __get_aa(item.authorizable_attribute_id)
    received_values = sorted([json.loads(_.json()) for _ in item.values],
                             key=lambda k: k["name"])
    __validate_reissuing(aa, received_values)
    __check_mandatory_info_fields(aa, received_values)
    __check_wrong_info_fields(aa, received_values)
    issued_credential = __issue_credential(aa.keypair,
                                           item.blind_sign_request.json())
    vc = ValidatedCredentials(aaid=aa.authorizable_attribute_id,
                              value=json.dumps(received_values))
    DBSession.add(vc)

    __check_optional_values(aa, item.optional_values)
    for option in item.optional_values:
        option = json.loads(option.json())
        s = Statistics(
            aaid=aa.authorizable_attribute_id,
            name=option["name"],
            value=option["value"],
        )
        DBSession.add(s)

    DBSession.commit()
    return json.loads(issued_credential)