This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import sleep | |
import requests | |
UNSTABLE_API = "https://httpbin.org/status/200,500" | |
def notsodumbretry(max_attempts, retry_backoff, backoff_exponential): | |
succeeded = False | |
attempts = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
UNSTABLE_API = "https://httpbin.org/status/200,500,503,401" | |
def dumbretry(): | |
succeeded = False | |
attempts = 0 | |
while not succeeded: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
api_1 | [12/May/2023 17:42:32] "POST /notes HTTP/1.1" 200 80 | |
relayer_1 | note-created event published to Kafka | |
consumer_1 | {'name': 'note-created', 'note': {'id': 3, 'title': 'My Note Title', 'content': 'This is the content of my note', 'created_at': '2023-05-12 17:42:32', 'updated_at': '2023-05-12 17:42:32'}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from jaiminho.send import save_to_outbox | |
@save_to_outbox | |
def publish_note_created(note_dict): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker-compose run api python manage.py migrate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3.10-slim-buster | |
WORKDIR /app | |
COPY requirements.txt . | |
RUN pip install -r requirements.txt | |
COPY . /app | |
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
django==4.2 | |
django-jaiminho==1.1.1 | |
kafka-python==2.0 | |
black==23.3 | |
pytest-django==4.5.2 | |
pytest==7.3.1 | |
pytest-mock==3.10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import admin | |
from django.urls import path, include | |
urlpatterns = [ | |
path("admin/", admin.site.urls), | |
path("", include("notes.urls")), | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.urls import path | |
from . import views | |
urlpatterns = [ | |
path("notes", views.note_view, name="note_view"), | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from django.db import transaction | |
from django.http import JsonResponse | |
from django.views.decorators.csrf import csrf_exempt | |
from .kafka_producer import publish_note_created | |
from .models import Note | |
NewerOlder