dwyl / dwylbot

:robot: Automating our GitHub Workflow to improve team communication/collaboration and reduce tedious repetition!
28 stars 7 forks source link

wait, check, comment #58

Closed SimonLab closed 7 years ago

SimonLab commented 7 years ago

Before reading more about processes I want to try the following steps. Although it's a simple solution and maybe not the best optimised one, I think it might work at this stage. We will be then able to iterate on this first implementation and with more knowledge about processes and concurrency build a stable and scalable implementation.

For each webhook post request:

SimonLab commented 7 years ago
  def new(conn, params) do
    IO.inspect params
    Process.sleep(60000)
    IO.inspect "wake up"
    conn
    |> put_status(200)
    |> json(%{ok: true})
  end

will return an error on Github side:

image Can we respond directly to Github before waiting with Process.sleep? Phoenix action required to return a conn, does this mean that another response will try to be sent back to Github?

SimonLab commented 7 years ago
  def new(conn, params) do
    # check error on params
    # check they are not already saved in postgres
    # save new error in postgres
    conn
    |> put_status(200)
    |> json(%{ok: true})
    Process.sleep(5000)
    IO.inspect "wake up"
    # check if errors still in postgres
    # if yes comment with error message on the issue
    conn
    |> put_status(:ok)
    |> json(%{sendback: true})
  end

This code seems to resolve the Timeout issue on Github. We are sending back a response as soon as the server receive the webhook request. We then wait a bit and send another response (which I think will be lost somewhere). It feels a bit strange to send back two responses but this works at the moment

ghost commented 7 years ago

Delay feature works 👍