Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View antunesleo's full-sized avatar

Leonardo Antunes antunesleo

View GitHub Profile
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
import requests
UNSTABLE_API = "https://httpbin.org/status/200,500,503,401"
def dumbretry():
succeeded = False
attempts = 0
while not succeeded:
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'}}
from jaiminho.send import save_to_outbox
@save_to_outbox
def publish_note_created(note_dict):
docker-compose run api python manage.py migrate
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"]
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
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path("admin/", admin.site.urls),
path("", include("notes.urls")),
]
from django.urls import path
from . import views
urlpatterns = [
path("notes", views.note_view, name="note_view"),
]
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