Skip to content

Instantly share code, notes, and snippets.

View agusrichard's full-sized avatar

Agus Richard Lubis agusrichard

View GitHub Profile
version: "3.8"
services:
app:
build: .
environment:
- FLASK_ENV=development
- FLASK_APP=app.py
ports:
- "5000:5000"
volumes:
FROM python:3.9-alpine
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
WORKDIR /app
COPY . /app
RUN pip install --upgrade pip
RUN pip install -r /app/requirements.txt
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from config import Config, make_celery
db = SQLAlchemy()
app = Flask(__name__)
app.config.from_object(Config) # Set Flask app configuration from Config class
db = SQLAlchemy(app)
from flask import request
from http import HTTPStatus
from threading import Thread
from app import app, db
from tasks import upload_task
from models import File, UploadStatus
from file import process_file_to_stream, upload_file, upload_file_from_stream
from app import celery
from app import db
from models import File, UploadStatus
from file import upload_file_from_stream
@celery.task()
def upload_task(file_id: int, file_dict: dict):
"""
import io
import boto3
import base64
from datetime import datetime
from werkzeug.utils import secure_filename
from werkzeug.datastructures import FileStorage
from app import app
# Setting up S3 client
import enum
from sqlalchemy import Enum
from app import db
class UploadStatus(enum.Enum):
"""
Serves as enum values for upload_status column of files table
(either PENDING, PROCESSING, COMPLETE OR ERROR)
import os
from flask import Flask
from celery import Celery
from dotenv import load_dotenv
load_dotenv()
class Config:
"""
SQLALCHEMY_DATABASE_URI=sqlite:///db.sqlite3
SQLALCHEMY_TRACK_MODIFICATIONS=False
AWS_ACCESS_KEY=<YOUR_AWS_ACCESS_KEY>
AWS_ACCESS_SECRET=<YOUR_AWS_ACCESS_SECRET>
S3_BUCKET_NAME=<YOUR_S3_BUCKET_NAME>
S3_BUCKET_BASE_URL=<YOUR_S3_BUCKET_BASE_URL>
CELERY_BROKER_URL=redis://redis:6379/0
CELERY_RESULT_BACKEND=redis://redis:6379/0
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": [