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

perform checks #53

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

perform checks #53

wants to merge 2 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Jun 7, 2022

This PR starts running checks for all sites that exist when the server is started.
Each site gets its own genserver that will run a check on the sites specified interval.

So Far, this PR does NOT:

  1. add the feature of checking sites as soon as they are created unless the server is restarted.
  2. add the feature to remove site checks when they are deleted unless the server is restarted.
  3. do anything when a site check fails.

@ghost ghost requested review from isometriks and brianlavall June 7, 2022 12:25
@ghost ghost force-pushed the zjr/perform-checks branch from ce7531c to c0f4caa Compare June 7, 2022 12:51
@ghost ghost requested a review from malssid June 7, 2022 12:51
@ghost ghost force-pushed the zjr/perform-checks branch from c0f4caa to 242cd83 Compare June 7, 2022 12:55
lib/situation_room/check/check_gen.ex Outdated Show resolved Hide resolved
lib/situation_room/check/check_make.ex Outdated Show resolved Hide resolved
lib/situation_room/check/check_make.ex Outdated Show resolved Hide resolved
"""
use Tesla

adapter(Tesla.Adapter.Hackney)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be curious to try the Finch adapter here instead of Hackney. Unless there was specific reason that Hackney was chosen?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason Hackney was chosen - I can certainly use Finch. What kind of perks does Finch have over Hackney?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am currently using Finch and I must say - I did like the error messages that Hackney would give me when I passed invalid URLs into requests. This should not be that much of a problem because in order for a site to be checked, it has to pass an ecto validation when the site is created. Since this is the case, is there any value in testing for invalid URLs when performing site checks?

{:ok, response} ->
{:ok, %{"status" => response.status, "response_time" => time / 1000}}

{:error, {reason}} ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what case is this the return tuple vs the pattern on line 19? Looking at the Tesla.Env.result() typing, this pattern doesn't seem to be a possible return type.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were random cases where a tuple was being returned in my tests, so I added this in to pattern match those cases.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After switching adapters, I think that response tuple may have been specific to Hackney? Now I do not receive them.

{:error, reason} ->
{:error, reason}
end
rescue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is being rescued here and why? Why the rescue vs graceful handling and/or just let the process die and restart?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prior to this, I thought of rescue as a 'catchall' to fallback on. In hindsight this is a poor way of dealing with an error that I was expecting. When given a bad input for the run function, such as a number or an empty string, the process will die. I suppose a function spec or a guard clause could catch this error as well. I will also look into graceful handling.

@isometriks
Copy link
Contributor

I think you might be tackling too many issues in this PR too. Maybe we can just make it about the checks and the GenServer can come later? You aren't fully finishing either feature so maybe just create a way to trigger a single check, or some kind of check manager that can call multiple checks, and handle all of the success and failures. Also take a look at implementing @behaviour so that we can have multiple Checkers and know we can pass the same information to each one.

@ghost
Copy link
Author

ghost commented Jun 7, 2022

I think you might be tackling too many issues in this PR too. Maybe we can just make it about the checks and the GenServer can come later? You aren't fully finishing either feature so maybe just create a way to trigger a single check, or some kind of check manager that can call multiple checks, and handle all of the success and failures. Also take a look at implementing @behaviour so that we can have multiple Checkers and know we can pass the same information to each one.

I like this idea. I will split this up into different PRs. One for the general check logic and one for the supervisor/genserver implementation.

@ghost ghost force-pushed the zjr/perform-checks branch from 242cd83 to 8c0d725 Compare June 7, 2022 15:33
@ghost ghost force-pushed the zjr/perform-checks branch from 8c0d725 to a50dbe7 Compare June 7, 2022 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants