Exemplo n.º 1
0
from flask import Flask
from flask_dramatiq import Dramatiq

Dramatiq.DEFAULT_BROKER = "dramatiq.brokers.redis:RedisBroker"

app = Flask(__name__)
dramatiq = Dramatiq(app)


@dramatiq.actor()
def my_actor():
    print("run task")


@app.route("/")
def myhandler():
    my_actor.send()
Exemplo n.º 2
0
from flask.helpers import safe_join
from .predictions import get_image_objects, get_image_description
from config import Config
from database import Image as DBImage, db, ImageObject, User
from PIL import Image
from urllib.parse import quote_plus
from datetime import datetime
import requests
import time
import io
import os
import base64
import uuid
import shutil

dramatiq = Dramatiq()


def getImage(image_id: str, access_token: str, quality: str) -> Image:
    image = None
    while image is None:
        try:
            response = requests.get(
                f'{Config.WORKER_BACKEND_SERVER}/api/image/{image_id}/{quality}?uuid={quote_plus(access_token)}',
                stream=True)
            if response.status_code >= 400 and response.status_code < 500:
                raise requests.exceptions.HTTPError()
            image = Image.open(response.raw)
        except requests.exceptions.ConnectionError:
            time.sleep(0.5)
    return image
Exemplo n.º 3
0
import random

import requests
from flask_dramatiq import Dramatiq
from flask_sse import sse
from models import Webhook, get_connection

# Initialise the dramatiq object, that is later called for decorating the worker methods
flask_dramatiq_obj = Dramatiq()


@flask_dramatiq_obj.actor()
def upload_product_csv_records(csv_records: list) -> None:
    """
    This is the background function that is responsible for uploading the CSV records onto the database.
    :param csv_records: list of product records
    """
    total_records = len(csv_records)
    connection = get_connection()

    cursor = connection.cursor()
    for index, product_dict in enumerate(csv_records):
        # Use Upsert logic as application dictates that record must be updated
        sql_statement = """
        INSERT INTO product (sku, name, description, active)
        VALUES (%s,%s,%s, %s)
        ON DUPLICATE KEY UPDATE
        name=%s,
        description=%s,
        active=%s;
        """