Siempre asigna un valor por defecto a los campos booleanos

Es relativamente común ver campos booleanos en una base de datos para representar algún estado y al mismo tiempo es igualmente común ver que por un descuido esta columna pueda y llegue a tener valores nulos. Esto puede acarrear errores de semántica y de lógica. Para evitar este problema es una buena práctica definir los campos como null: false y además siempre dar un valor por defecto, por ejemplo admin: false....

abril 18, 2023 · Me

Como crear un productor personalizado en Broadway

Broadway es una herramienta construida sobre GenStage, concurrente de varias etapas para crear pipelines de ingesta y procesamiento de datos. Es decir, esta biblioteca nos permite consumir y procesar información de fuentes como un Message Broker (Kafka, RabbitMQ, etc.). Por si fuera poco, viene con una serie de características integradas que nos permiten diseñar nuestros pipelines con una gran flexibilidad: Back-pressure Concurrencia y procesamiento por lotes Rate limiting Varios producers out of the box La posibilidad de crear custom producers Entre otras....

febrero 21, 2023 · Me

Useful Patterns to communicate with external services

Communicating with external services like a third-party API REST is hard, not only because the contract is designed by someone else. Also, now you need to consider the Fallacies of Distributed Systems. Calls to external services can fail for multiple reasons unrelated to business concerns. You can receive a timeout error, the network can fail, bandwith related errors, etc. However, some patterns exist to build more reliable systems when dealing with network calls....

enero 3, 2023 · Me

How to manage business logic in rails

One of the main problems, when an application grows, is how to keep organized the business logic. Following the “rails way” can conduce to a common result called obese models & obese controllers. This means that your models and your controllers keep growing when you continuously add the business logic in the same place. Another inconvenience is that you are coupling your use cases or business logic to the infrastructure (the framework, the database, and the input interface)....

octubre 25, 2022 · Me

Testing the Phoenix controllers without rebinding the conn

Maybe, for readability purposes, you prefer to avoid variable rebinding. For example, take this generated test code from mix phx.gen.auth task: test "renders log in page", %{conn: conn} do conn = get(conn, Routes.user_session_path(conn, :new)) response = html_response(conn, 200) assert response =~ "Log in" assert response =~ "Register</a>" assert response =~ "Forgot password?</a>" end It’s completely ok. But, you can prefer something like this: test "renders log in page", %{conn: conn} do response = conn |> get(Routes....

mayo 11, 2022 · Me