-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Library package is moved to `autopoller` instead of `main`. Signed-off-by: Elis Lulja <[email protected]>
- Loading branch information
1 parent
f338f67
commit b0051e2
Showing
5 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package autopoller | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func main() { | ||
ctx, canc := context.WithCancel(context.Background()) | ||
defer canc() | ||
|
||
exitChan := make(chan struct{}) | ||
|
||
p := New(10, false) | ||
var freq int = 10 | ||
p.AddPage(&WebsitePage{ | ||
ID: "euronics-digital", | ||
URL: "https://www.euronics.it/console/sony-computer/playstation-5-digital-edition/eProd202008907/", | ||
PollSettings: PollSettings{ | ||
Type: FixedPolling, | ||
Frequency: &freq, | ||
}, | ||
UserAgents: []string{"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"}, | ||
}, do) | ||
p.AddPage(&WebsitePage{ | ||
ID: "euronics-standard", | ||
URL: "https://www.euronics.it/console/sony-computer/playstation-5/eProd202008906/", | ||
PollSettings: PollSettings{ | ||
Type: FixedPolling, | ||
Frequency: &freq, | ||
}, | ||
UserAgents: []string{"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"}, | ||
}, do) | ||
|
||
signalChan := make(chan os.Signal, 1) | ||
signal.Notify( | ||
signalChan, | ||
syscall.SIGHUP, // kill -SIGHUP XXXX | ||
syscall.SIGINT, // kill -SIGINT XXXX or Ctrl+c | ||
syscall.SIGQUIT, // kill -SIGQUIT XXXX | ||
) | ||
|
||
go p.Start(ctx, exitChan) | ||
|
||
<-signalChan | ||
fmt.Println("os.Interrupt - shutting down...") | ||
canc() | ||
|
||
// PERFORM GRACEFUL SHUTDOWN HERE | ||
<-exitChan // Wait for euronics to finish | ||
|
||
fmt.Println("exiting for real") | ||
os.Exit(0) | ||
} | ||
|
||
func do(w *WebsitePage, r *http.Response, e error) { | ||
customFormatter := new(log.TextFormatter) | ||
customFormatter.TimestampFormat = "2006-13-02 15:04:05" | ||
customFormatter.FullTimestamp = true | ||
l := log.WithFields(log.Fields{"id": w.ID, "resp": r.Status}) | ||
l.Logger.SetFormatter(customFormatter) | ||
l.Info("got response") | ||
defer r.Body.Close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package autopoller | ||
|
||
import ( | ||
"net/http" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package autopoller | ||
|
||
import ( | ||
"context" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package autopoller | ||
|
||
import ( | ||
"math/rand" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters