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

Demo Weather Forcaster Secnario - Occasional URL Fetch Failure #2

Open
SeanRiggs opened this issue Dec 24, 2022 · 0 comments
Open

Demo Weather Forcaster Secnario - Occasional URL Fetch Failure #2

SeanRiggs opened this issue Dec 24, 2022 · 0 comments

Comments

@SeanRiggs
Copy link

adapting this scenario to my Huginn instance it works beautifully, but occasionally I will not get a daily report. When I check the logs, the error I get is a URL Fetch Error on the agent: Pull the NWS forecast for the requested location Logs.

Begining of error log:

Error when fetching url: Failed: #<Faraday::Response:0xebbb94a8 @on_complete_callbacks=[], @env=#<Faraday::Env @method=:get @body="{\n "correlationId": "e23e53a",\n "title": "Unexpecte...

If I manually run the URL pull and Forcast Pull agent, it will resubmit and deliver the forcast as expected.

My thought is that I would add JSON to the agent to reattempt on failure. for example:


{
"expected_update_period_in_days": "365",
"url": "{{ url }}",
"type": "json",
"mode": "merge",
"extract": {
"today": {
"path": "$.properties.periods.[0].detailedForecast"
},
"tonight": {
"path": "$.properties.periods.[1].detailedForecast"
},
"datestamp": {
"path": "$.properties.updateTime"
}
},
"user_agent": "158.101.13.100:3000",
"retry": {
"max_tries": 5,
"on_failure": {
"notify": {
"to": "[email protected]",
"subject": "The weather forecast agent is experiencing a downtime"
}
}
}
}

The addiiton above is really to show retries up to 5 times ... then to notify recipient on failure ... (that part is wrong for sure) but I thought the retries would work?

Thought now is to create a Log monitoring agent that will monitor for failure, then send event to trigger agent which initiates rerun of the agent "pull NWS forcast" However, I cannot find a log monitor agent.

I know there is a way to make an agent, but I have not figured it out. The Ruby code would look something like this:


require the necessary libraries:
require "file"
require "huginn_agent"

define the log monitoring agent class:
class LogMonitorAgent < HuginnAgent
def check
- read the logs of the other agent
logs = File.read("/path/to/logs/other_agent.log")

check for a certain condition in the logs:
if logs.include?("Error")
create and trigger an event if the condition is met
event = Event.new(payload: { message: "Error detected in logs" })
create_event(event)
end
end
end


(I would "#" the colon items in the ruby syntax above, but the markdown in Github makes it a header)

Thought I would try to contribute as this is the best forcasting agent for Huginn I use and love it pulls api right from NWS via geo location.

Can you help suggest improvement to adjust for occasional URL fetching errors?

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

No branches or pull requests

1 participant