Skip to content

Demo Weather Forcaster Secnario - Occasional URL Fetch Failure #2

@SeanRiggs

Description

@SeanRiggs

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@gmail.com",
"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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions