Skip to content

Commit a178499

Browse files
committed
feat: mock mode
1 parent edf8277 commit a178499

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,17 @@ Create a `env.json` file with the following content **(this file can also be obt
6666
],
6767
"login_users": [
6868
{"username": "scraping-site-username", "password": "scraping-site-password"}
69-
]
69+
],
70+
"mock_mode": true
7071
}
7172
```
7273
7374
### *3.* Develop / Deploy a scraper using `rtcv_scraper_client`
7475
7576
You can now prefix your scraper's run command with `rtcv_scraper_client` and the scraper client program will run a webserver as long as your scraper runs where via you can communicate with RT-CV.
7677
78+
Set `"mock_mode": true` in ur env.json for development
79+
7780
If you have for a NodeJS project you can run your program like this:
7881
7982
```sh

api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (c *serverConn) DoRequest(method, path string, body, unmarshalResInto inter
137137
if err != nil {
138138
attempt++
139139
if attempt > 3 {
140-
return fmt.Errorf("%s, retried 4 times", err.Error())
140+
return fmt.Errorf("%s retried 4 times", err.Error())
141141
}
142142
time.Sleep(time.Second * time.Duration(attempt) * 2)
143143
continue

main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type Env struct {
1717
PrimaryServer EnvServer `json:"primary_server"`
1818
AlternativeServers []EnvServer `json:"alternative_servers"`
1919
LoginUsers []EnvUser `json:"login_users"`
20+
MockMode bool `json:"mock_mode"`
2021
}
2122

2223
func (e *Env) validate() error {
@@ -100,6 +101,11 @@ func main() {
100101
if err != nil {
101102
log.Fatal(err)
102103
}
104+
105+
if env.MockMode {
106+
api.SetMockMode()
107+
}
108+
103109
fmt.Println("credentials set")
104110
fmt.Println("testing connections..")
105111
testServerConnections(api)
@@ -130,6 +136,9 @@ func main() {
130136
}
131137

132138
func testServerConnections(api *API) {
139+
if api.MockMode {
140+
return
141+
}
133142
for _, conn := range api.connections {
134143
err := conn.Get("/api/v1/health", nil)
135144
if err != nil {

0 commit comments

Comments
 (0)