Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Convert waiting and starting status to 202 #2161

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lucky-cats-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@core/sync-service": patch
---

Return `202` for `waiting` and `starting` health status - accepts requests but will fail to service them.
3 changes: 3 additions & 0 deletions packages/sync-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,8 @@ ARG RELEASE_NAME=electric
COPY --from=builder /app/_build/prod/rel/${RELEASE_NAME} ./
RUN mv /app/bin/${RELEASE_NAME} /app/bin/entrypoint


HEALTHCHECK --start-interval=2s --start-period=10s CMD curl --fail http://localhost:${ELECTRIC_PORT-3000}/v1/health || exit 1

ENTRYPOINT ["/app/bin/entrypoint"]
CMD ["start"]
4 changes: 2 additions & 2 deletions packages/sync-service/lib/electric/plug/health_check_plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ defmodule Electric.Plug.HealthCheckPlug do

{status_code, status_text} =
case get_service_status.() do
:waiting -> {503, "waiting"}
:starting -> {503, "starting"}
:waiting -> {202, "waiting"}
:starting -> {202, "starting"}
:active -> {200, "active"}
:stopping -> {503, "stopping"}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ defmodule Electric.Plug.HealthCheckPlugTest do
end

@tag connection_status: :waiting
test "returns 503 when in waiting mode", ctx do
test "returns 202 when in waiting mode", ctx do
conn =
conn(ctx)
|> HealthCheckPlug.call([])

assert conn.status == 503
assert conn.status == 202
assert Jason.decode!(conn.resp_body) == %{"status" => "waiting"}
end

@tag connection_status: :starting
test "returns 503 when in starting mode", ctx do
test "returns 202 when in starting mode", ctx do
conn =
conn(ctx)
|> HealthCheckPlug.call([])

assert conn.status == 503
assert conn.status == 202
assert Jason.decode!(conn.resp_body) == %{"status" => "starting"}
end

Expand Down
Loading