Skip to content

Commit

Permalink
update and automate
Browse files Browse the repository at this point in the history
  • Loading branch information
ofpiyush committed Nov 25, 2021
1 parent fb1a6ff commit 8d927f3
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/pypi-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Upload Python Package

on:
release:
types: [created]

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
run: |
echo ${{github.event.release.tag_name}} > version.txt
python setup.py sdist bdist_wheel
twine upload dist/*
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,5 @@ dmypy.json

# Pyre type checker
.pyre/

version.txt
8 changes: 6 additions & 2 deletions examples/simple/main.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import logging
import os
import typing

from fastapi import FastAPI
from fastapi.routing import APIRouter
from fastapi.params import Header
from fastapi_cloud_tasks.taskroute import TaskRouteBuilder
from fastapi_cloud_tasks.utils import queue_path
from pydantic import BaseModel

TaskRoute = TaskRouteBuilder(
# Base URL where the task server will get hosted
base_url=os.getenv("TASK_LISTENER_BASE_URL", default="https://6045-49-207-221-153.ngrok.io"),
base_url=os.getenv("TASK_LISTENER_BASE_URL", default="https://d860-35-208-83-220.ngrok.io"),
# Full queue path to which we'll send tasks.
# Edit values below to match your project
queue_path=queue_path(
Expand All @@ -29,7 +31,9 @@ class Payload(BaseModel):


@task_router.post("/hello")
async def hello(p: Payload = Payload(message="Default")):
async def hello(p: Payload = Payload(message="Default"), x_cloudtasks_taskretrycount: typing.Optional[int] = Header(0)):
if x_cloudtasks_taskretrycount < 5:
raise Exception("Noooo")
logger.warning(f"Hello task ran with payload: {p.message}")


Expand Down
3 changes: 2 additions & 1 deletion fastapi_cloud_tasks/delayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def _headers(self, *, values):
cookies = err_val(request_params_to_args(self.route.dependant.cookie_params, values))
if len(cookies) > 0:
headers["Cookies"] = "; ".join([f"{k}={v}" for (k, v) in cookies.items()])
return headers
# Always send string headers and skip all headers which are supposed to be sent by cloudtasks
return {str(k): str(v) for (k,v) in headers.items() if not str(k).startswith("x_cloudtasks_")}

def _url(self, *, values):
route = self.route
Expand Down
11 changes: 10 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
from setuptools import setup

with open('version.txt') as f:
version = f.read().strip()

with open('README.md', encoding='utf-8') as f:
long_description = f.read().strip()


setup(
name="fastapi-cloud-tasks",
version="0.0.1",
version=version,
description="Trigger delayed Cloud Tasks from FastAPI",
long_description=long_description,
long_description_content_type='text/markdown',
licesnse="MIT",
packages=["fastapi_cloud_tasks"],
install_requires=["google-cloud-tasks", "fastapi"],
Expand Down

0 comments on commit 8d927f3

Please sign in to comment.