Example #1
0
def retry(
    *,
    db: Session = Depends(deps.get_db),
    job_id: uuid.UUID,
    retry_input: Optional[schemas.JobUpdate] = None,
) -> Any:
    job = crud.job.get(db, job_id)

    if not job:
        raise HTTPException(
            status_code=requests.codes["not_found"],
            detail=f"Job with id {job_id} not found",
        )

    try:
        crud.job.retry(db, db_obj=job, retry_input=retry_input)
    except JobNotRetriable:
        raise HTTPException(
            status_code=requests.codes["unprocessable"],
            detail="The job can't be retried",
        )

    celery_app.send_task("app.worker.process_job", args=[job.id])

    return job
Example #2
0
def test_celery(
    msg: Msg, current_user: UserInDB = Depends(get_current_active_superuser)):
    """
    Test Celery worker
    """
    celery_app.send_task("app.worker.test_celery", args=[msg.msg])
    return {"msg": "Word received"}
Example #3
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 #4
0
def init_db(db: Session) -> None:
    # Tables should be created with Alembic migrations
    # But if you don't want to use migrations, create
    # the tables un-commenting the next line
    # Base.metadata.create_all(bind=engine)

    user = crud.user.get_by_email(db, email=settings.FIRST_SUPERUSER)
    if not user:
        deck = crud.deck.create(db,
                                obj_in=schemas.SuperDeckCreate(title="Default",
                                                               public=True))
        # deck = models.Deck(id=1, title="Default")
        # db.add(deck)
        # db.commit()

        user_in = schemas.SuperUserCreate(
            email=settings.FIRST_SUPERUSER,
            password=settings.FIRST_SUPERUSER_PASSWORD,
            username="******",
            is_superuser=True,
        )
        user = crud.user.super_user_create(db, obj_in=user_in)  # noqa: F841

        crud.deck.assign_owner(db, db_obj=deck, user=user)
        logger.info("Sending celery task")
        celery_app.send_task("app.worker.load_jeopardy_facts")
        celery_app.send_task("app.worker.load_quizbowl_facts")
Example #5
0
def route_test_celery(word):
    current_user = get_current_user()  # type: User
    if not current_user:
        abort(400, "Could not authenticate user with provided token")
    elif not check_if_user_is_superuser(current_user):
        abort(400, "Not a superuser")
    celery_app.send_task("app.worker.test_celery", args=[word])
    return ({"msg": "Word received"}, 201)
Example #6
0
def route_test_celery(msg: Msg, current_user: UserInDB = Depends(get_current_user)):
    """
    Test Celery worker
    """
    if not check_if_user_is_superuser(current_user):
        raise HTTPException(status_code=400, detail="Not a superuser")
    celery_app.send_task("app.worker.test_celery", args=[msg.msg])
    return {"msg": "Word received"}
def test_celery(
    msg: schemas.Msg,
    current_user: models.User = Depends(deps.get_current_active_superuser),
) -> Any:
    """
    Test Celery worker.
    """
    celery_app.send_task("app.worker.test_celery", args=[msg.msg])
    return {"msg": "Word received"}
def update_preloaded_facts(
        *,
        current_user: models.User = Depends(
            deps.get_current_active_superuser),  # noqa
) -> Any:
    """
    Update preloaded facts.
    """
    celery_app.send_task("app.worker.clean_up_preloaded_facts")
    return True
Example #9
0
def start_run(*,
              username: str = Cookie(None),
              part_id: int,
              rec_id: int,
              run: RunCreate,
              db: Session = Depends(deps.get_db)):
    run.is_running = True
    fresh_run = crud.run.create_with_recoding(db_session=db,
                                              obj_in=run,
                                              recording_id=rec_id)
    celery_app.send_task(
        "app.worker.run",
        args=[part_id, rec_id, fresh_run.id, -100, 0, 0, 0, 0, 0, 0, username])
    return fresh_run
Example #10
0
def post_job(
    *, db: Session = Depends(deps.get_db), job_input: schemas.JobCreate
) -> Any:
    try:
        job = crud.job.create(db, obj_in=job_input)
    except JobDuplicated:
        raise HTTPException(
            status_code=requests.codes["conflict"],
            detail="An active job for that (import_url, export_url) already exists",
        )

    celery_app.send_task("app.worker.process_job", args=[job.id])

    return job
Example #11
0
async def user(user: CreateUser):
    hash_password = get_password_hash(user.password)
    await Users.objects.create(email=user.email, phone=user.phone, password=hash_password, username=user.username)
    task = celery_app.send_task("app.api.api_v1.tasks.emails.decoratorEmail",
                                args=[user.email, "".join([str(random.randint(1, 9)) for i in range(6)])])
    print(task, "---------")
    return create_access_token(data={"username": user.username, "email": user.email})
Example #12
0
def gen_datestrs(
    *,
    db: Session = Depends(deps.get_db),
    year: int
    # current_user: models.User = Depends(deps.get_current_active_user),
):
    db_obj = db.query(models.Martyrology).distinct("datestr")
    # db_obj = list(db_obj)[:100]
    datestrs = [i.datestr for i in db_obj]
    # chunks = []
    # for i in range(len(datestrs) // 100):
    #     chunks.append(datestrs[i * 100 : i * 100 + 100])
    # print(chunks)
    # results = celery_app.send_task("app.worker.resolve_datestrs", args=[chunks, year])
    # results.get()
    # calendar_dates = [i.get() for i in results.children[0]]
    results = celery_app.send_task("app.worker.linear_resolve_datestrs",
                                   args=[[i.datestr for i in db_obj], year])
    calendar_dates = results.get()
    mapping = {}
    for i, date in enumerate(calendar_dates):
        try:
            mapping[date].append(datestrs[i])
        except KeyError:
            mapping[date] = [datestrs[i]]
    return mapping
Example #13
0
async def test_progress_ticket_data() -> Any:
    task = celery_app.send_task("app.worker.progress_ticket_data")
    RUNNING_TASKS.append(task)
    if task:
        return {
            'task_id': task.id,
        }
Example #14
0
async def test_celery(
    *,
    msg: schemas.Msg,
) -> Any:
    """
    Test Celery worker.
    """
    task = celery_app.send_task("app.worker.test_celery", args=[msg.msg])
    print("task", task, "status", task.status)

    task_two = celery_app.send_task("app.worker.test_test")
    RUNNING_TASKS.append(task_two)
    print("task_two", task_two, "status", task_two.status)

    return {
        "task_id": task_two.id,
    }
Example #15
0
async def update_status(
    owner_id: int,
    status: StatusRequest,
    db: Session = Depends(deps.get_db),
    current_user: models.User = Depends(deps.get_current_active_superuser),
) -> Any:
    """
    Update Automatic Debit Status.
    """
    debit = crud.debit.get_by_owner(db, owner_id=owner_id)
    if not debit:
        raise HTTPException(status_code=sts.HTTP_404_NOT_FOUND,
                            detail="Not Found automatic debit request by id")

    obj_in = DebitUpdate(status=status)
    debit_out = crud.debit.update_status(db, db_obj=debit, obj_in=obj_in)
    
    if status in (StatusRequest.canceled, StatusRequest.approved):
        user = crud.user.get(db, id=debit.owner_id)
        celery_app.send_task("app.tasks.send_email.email_task",
                             args=[status, user.email])
    return debit_out
Example #16
0
def create_mobile_value(*,
                        username: str = Cookie(None),
                        part_id: int,
                        rec_id: int,
                        tv: TimestampValues,
                        db: Session = Depends(deps.get_db)):
    files = crud.file.get_multi_for_recording(db_session=db,
                                              recording_id=rec_id)
    for file in files:
        value = None
        if "ibi" in file.name.lower() and tv.ibi is not None:
            value = ValueCreate(timestamp=tv.timestamp, value1=tv.ibi)
        if "eda" in file.name.lower() and tv.eda is not None:
            value = ValueCreate(timestamp=tv.timestamp, value1=tv.eda)
        if "temp" in file.name.lower() and tv.temp is not None:
            value = ValueCreate(timestamp=tv.timestamp, value1=tv.temp)
        if "acc" in file.name.lower() and tv.acc_x is not None:
            value = ValueCreate(timestamp=tv.timestamp,
                                value1=tv.acc_x,
                                value2=tv.acc_y,
                                value3=tv.acc_z)

        if value is not None:
            crud.value.create_with_file(db_session=db,
                                        obj_in=value,
                                        file_id=file.id)

    current_run = crud.run.get_first_for_recording(db_session=db,
                                                   recording_id=rec_id)

    celery_app.send_task("app.worker.run",
                         args=[
                             part_id, rec_id, current_run.id, tv.timestamp,
                             tv.eda, tv.ibi, tv.temp, tv.acc_x, tv.acc_y,
                             tv.acc_z, username
                         ])
    return current_run
Example #17
0
async def start_spider(*, data: Data):
    """
    Start spider for apps with below information:
    - **update**: update app info in db, or not
    - **apps**: app info in a list
        - **product**: app name
        - **version**: app version
        - **vendor**: app vendor
    """

    task = celery_app.send_task("app.bgtasks.nvd_spider.spider",
                                args=[jsonable_encoder(data)])
    uid = str(uuid.uuid4())
    task_id = ''.join(uid.split('-'))
    await store_task_id(task_id)

    res = {"message": "success", 'task_id': task_id}
    return res
    def start_celery_task(self, media_id: UUID) -> ServiceResult:
        media = crud.media.get(self.db, id=media_id)
        if not media:
            return ServiceResult(AppException.MediaGet({"media_id": media_id}))

        from app.core.celery_app import celery_app
        from app.api.api_v1.endpoints.utils import RUNNING_TASKS

        if media.type == MediaType.IMPORT:
            task = celery_app.\
                send_task("app.worker.progress_ticket_data", args=[media.filepath])
        elif media.type == MediaType.CLAIMS:
            print("?")
            task = celery_app.\
                send_task("app.worker.progress_claim_data", args=[media.filepath])
        else:
            task = celery_app.send_task("app.worker.test_test")

        RUNNING_TASKS.append(task)
        result = {
            'task_id': task.id,
            'media_id': media.id,
        }
        return ServiceResult(result)
Example #19
0
def refresh_partner_urls(db: Session = Depends(get_db)):

    celery_app.send_task("app.worker.refresh_partner_urls")
    return 'Refreshing partner image_urls from ccb...', 200
Example #20
0
def send_partner_emails(db: Session = Depends(get_db)):

    celery_app.send_task("app.worker.queue_partner_emails")
    return 'Sending partner emails...', 200
Example #21
0
def sync_members(db: Session = Depends(get_db)):

    celery_app.send_task("app.worker.sync_members")
    return 'Syncing members from ccb...', 200
Example #22
0
def test_celery():
    """
    Test Celery worker.
    """
    celery_app.send_task("app.worker.test_celery", args=['szaa----'])
    return {"msg": "Word received"}
Example #23
0
def route_test_celery(word):
    celery_app.send_task('app.worker.test_celery', args=[word])
    return ({'msg': 'Word received'}, 201)
Example #24
0
def clean_queue(msg: schemas.Msg) -> Any:
    """
    Clean queue of stale entries
    """
    task = celery_app.send_task("app.worker.clean_queue", args=[msg.msg])
    return {"msg": f"Queue cleanup initiated as task {task.id}."}
Example #25
0
def route_test_celery(word):
    celery_app.send_task("app.worker.test_celery", args=[word])
    return ({"msg": "Word received"}, 201)
Example #26
0
async def scrape_jobs_task():
    celery_app.send_task("app.tasks.scrape_jobs_task")

    return {"message": "success"}
async def example_task():
    celery_app.send_task("app.task.example_task", args=["Hello World"])
    return {"message": "success"}
def test_fact_load(
        client: TestClient, superuser_token_headers: Dict[str, str]
) -> None:
    celery_app.send_task("app.worker.load_quizbowl_facts")