fetch

package
v0.0.0-...-b30125a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2021 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package fetch provides logic to fetch URLs to monitor from UptimeRobot.

Index

Constants

View Source
const (
	UptimeRobotAPIURL = "https://api.uptimerobot.com/v2/getMonitors"
	Interval          = 1 * time.Second
	Timeout           = 30 * time.Second
)

Variables

This section is empty.

Functions

func Fetch

func Fetch(uptimeRobotAPIKey string, out chan<- []string) (count int, err error)

Fetching the URLs to be monitored from UptimeRobot is easy; finding the best way to add them to the map of monitors has been difficult. Keep in mind that UptimeRobot API enforces a constraint: you can only fetch 50 monitors per request, not more.

Initialy I tried fetching a batch of URLs, then sending each URL one by one to the `found` channel (i.e. `chan string`). This worked fine until the map of monitors was large enough that polling all of them took longer than a poll tick (default 1m). At that point, only monitor could be added to the map during each poll cycle.

Next I tried changing `found` to `chan[] string`, and sending each batch of 50 (or less for the final batch). This worked better, but was still subject to the same consequence that only batch could be added per poll cycle.

So now I'm fetching *all* the URLs to be monitored (w/ as many requests as necessary), and sending them to the `found` channel in one (very) large batch.

Types

type GetMonitorsResponse

type GetMonitorsResponse struct {
	Pagination Pagination
	Monitors   []Monitor
}

type Monitor

type Monitor struct {
	URL string
}

type Pagination

type Pagination struct {
	Offset int
	Limit  int
	Total  int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL