Example #1
0
def print_items(background_tasks: BackgroundTasks):
    """
    print item info in background
    an example with
    """
    background_tasks.add_task(item_service.print_items_one_by_one, 1)
    return success(msg='Printing items now~')
Example #2
0
def delay_print_items(background_tasks: BackgroundTasks):
    """
    print item info in delayed mode
    :param background_tasks:
    :return:
    """
    background_tasks.add_task(
        item_service.print_items_one_by_one_in_another_process)
    return success(msg='launched print items delayed!')
Example #3
0
def update_item(item_id: int, item: Item):
    """
    update item info by item id
    """
    LOGGER.info('Update item with id: %d' % item_id)
    ok = item_service.update_item(item_id, item)
    if not ok:
        return error(data=None, msg='Cannot found item with id %d' % item_id)
    return success(item)
Example #4
0
def get_item(item_id: int):
    """
    get item info by item id
    """
    LOGGER.info('Get item with id: %d' % item_id)
    item = item_service.get_item(item_id)
    if not item:
        return error(msg='Cannot found item with id %d' % item_id)
    return success(item)
Example #5
0
async def upload_file(file: UploadFile = File(...)):
    filename = file.filename
    content = await file.read()
    decoded_content = content.decode('utf-8')
    LOGGER.info('Received file %s:\n%s' % (filename, decoded_content))
    return success({
        'filename': filename,
        'contentType': file.content_type,
        'size': len(decoded_content)
    })
Example #6
0
def health_check():
    """
    basic example
    :return:
    """
    return success(data={
        'name': app_name,
        'hash': md5hash(app_name),
    },
                   msg='Yes OK~')
Example #7
0
def get_items(keyword: Optional[str] = '',
              min_price: Optional[float] = -1.0,
              max_price: Optional[float] = -1.0):
    """
    an example with query
    :return:
    """
    if 0 <= max_price < min_price:
        return error(msg='invalid price range!')
    items = item_service.get_items(keyword, min_price, max_price)
    return success(data=items)
Example #8
0
def test_celery():
    """
    test celery example
    :return:
    """
    task = celery_app.send_task('service.celery.worker.get_item_price',
                                args=[1])
    LOGGER.info('triggered celery task: %s' % task)
    print(task.get())
    # background_tasks.add_task(on_celery_message, task)
    return success(msg='triggered celery test!')
Example #9
0
def health_check():
    return success({
        'name': app_name,
        'hash': md5hash(app_name),
    })
Example #10
0
def health_check():
    return success(data={
        'name': app_name,
        'hash': md5hash(app_name),
    },
                   msg='Yes OK~')