Update sleep timers

master
Jan-Lukas Else 2020-01-16 13:10:37 +01:00
parent 85adb26acd
commit 108571ac15
2 changed files with 16 additions and 14 deletions

View File

@ -85,13 +85,13 @@ func HandleMicroPub(w http.ResponseWriter, r *http.Request) {
} else { } else {
w.Header().Add("Location", location) w.Header().Add("Location", location)
w.WriteHeader(http.StatusAccepted) w.WriteHeader(http.StatusAccepted)
// Purge CDN in 10 seconds, send webmentions, post to social media // Purge CDN after 30 seconds, send webmentions, post to social media
go func() { go func() {
time.Sleep(30 * time.Second)
if SelectedCdn != nil { if SelectedCdn != nil {
time.Sleep(10 * time.Second)
SelectedCdn.Purge(location) SelectedCdn.Purge(location)
time.Sleep(10 * time.Second)
} }
time.Sleep(10 * time.Second)
// Send webmentions // Send webmentions
go SendWebmentions(location) go SendWebmentions(location)
go func() { go func() {

View File

@ -42,17 +42,19 @@ func SendWebmentions(url string) {
func filterLinks(links []string) []string { func filterLinks(links []string) []string {
var filteredLinks []string var filteredLinks []string
for _, link := range links { checkPrefix := func(link string, prefix string) bool {
if strings.HasPrefix(link, strings.TrimSuffix(BlogUrl, "/")) { return strings.HasPrefix(link, strings.TrimSuffix(prefix, "/"))
continue }
} checkAny := func(link string) bool {
ignored := false for _, ignoredUrl := range IgnoredWebmentionUrls {
for _, ignoredURL := range IgnoredWebmentionUrls { if checkPrefix(link, ignoredUrl) {
if !ignored && strings.HasPrefix(link, strings.TrimSuffix(ignoredURL, "/")) { return true
ignored = true
} }
} }
if ignored != true { return false
}
for _, link := range links {
if !(checkPrefix(link, BlogUrl) || checkAny(link)) {
filteredLinks = append(filteredLinks, link) filteredLinks = append(filteredLinks, link)
} }
} }
@ -181,10 +183,10 @@ func returnSuccess(target string, w http.ResponseWriter, r *http.Request) {
} else { } else {
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
} }
// Purge CDN in 10 seconds // Purge CDN after 30 seconds
go func() { go func() {
time.Sleep(30 * time.Second)
if SelectedCdn != nil { if SelectedCdn != nil {
time.Sleep(10 * time.Second)
SelectedCdn.Purge(target) SelectedCdn.Purge(target)
} }
}() }()