Skip to content

Instantly share code, notes, and snippets.

@chi-feng
Last active July 18, 2022 21:08
Show Gist options
  • Save chi-feng/cb52336f6a720fe9fe8f54327048f29f to your computer and use it in GitHub Desktop.
Save chi-feng/cb52336f6a720fe9fe8f54327048f29f to your computer and use it in GitHub Desktop.
Asynchronous Tasks with FastAPI and Celery
sequenceDiagram
    participant Client
    participant App 
    participant Database 
    participant Broker as Broker (redis)
    participant Worker as Celery Worker
    Client->>App: POST /api/document/create
    activate App
    App->>Database: Insert document
    App->>Broker: Enqueue a new task
    App->>Client: Response with document ID 
    deactivate App
    Worker->>Broker: Worker picks up task
    activate Worker
    Worker->>Database: Write result database and EFS
    deactivate Worker
    Client->>App: GET /api/document/resource
    activate App
    App->>Database: Fetch document resource
    App->>Client: Appropriate response
    deactivate App
Loading
flowchart TD
    Import
    Import --> bibtex["BibTeX"]
    Import --> code["ID-like"]
    code --> DOI["DOI via CrossRef"]
    code --> PMID["PMID via PubMed"]    
    code --> ArxID["ArXivID via ArXiv"]
    DOI -->|bibtex|bibtex
    PMID -->|bibtex|bibtex    
    ArxID -->|bibtex|bibtex    
    bibtex --> Single
    bibtex --> Multiple
    Single --> ReviewSingle
    ReviewSingle --> BibMergeDialog
    ReviewSingle --> Create[Create]
    ReviewSingle --> Skip
    Multiple --> ReviewMultiple
    ReviewMultiple --> Create[Create]
    ReviewMultiple --> Skip
    ReviewMultiple --> ReviewMultipleDialog
Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment