add logic to perform site checks - #54
Conversation
5cdef1e to
0bb6a3f
Compare
63f5aaa to
62122af
Compare
cbe1a12 to
5348f9d
Compare
| @behaviour SituationRoom.Check.Behaviour | ||
|
|
||
| @impl true | ||
| def run(%SituationRoom.Site.Check{} = check) do |
There was a problem hiding this comment.
Can we use a more descriptive function name here?
There was a problem hiding this comment.
My idea on all these checks was to have them all have a @behaviour and thus have the same method name on all of them so we can do something like:
head_checks = [
Checks.StatusCode,
Checks.Outage
]
head_checks
|> Enum.map(fn module -> apply(module, "run", site))but we could still probably rename them to something else
| {:ok} | ||
| end | ||
|
|
||
| def do_outage(%SituationRoom.Site.Check{} = check, _reason) do |
There was a problem hiding this comment.
Can this be called create_new_outage()? And then the method that would mark an outage resolved would be something like resolve_outage()?
| add :site_id, references(:sites), null: false | ||
| add :status_code, :integer, null: false | ||
| add :response_time, :float, null: false | ||
| add :type, :string, default: "head", null: false |
There was a problem hiding this comment.
It would be better practice to create a new migration file for this instead of editing a previous one. That way we don't have to all reset our databases to run this.
| add :response_time, :float, null: false | ||
| add :type, :string, default: "head", null: false | ||
| add :headers, {:array, :map} | ||
| add :body, :string |
There was a problem hiding this comment.
Is this going to store the whole body of the response from the check?
There was a problem hiding this comment.
Same question here? We definitely don't want/need to store any/all of that data.
|
|
||
| case response do | ||
| {:ok, %Tesla.Env{} = env} -> | ||
| %Check{ |
There was a problem hiding this comment.
These check structs don't need to be the the schema structs. You could do a defstruct somewhere and just use it as a DTO. Then each check could insert any information it wanted (by passing both to run), or you could just create the ecto struct somewhere else and not let the checks know about it.
The other option if we do want to pass around the ecto structs is you can make virtual fields on them so they can hold information that doesn't get persisted to the database. (Like Brian's comment about the body field)
This PR implements the logic to check a site's status code and response time.