File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,8 @@ plugins:
32
32
database : " codeflow"
33
33
uri : " mongodb://mongo:27017"
34
34
ssl : false
35
+ connection_timeout : 3
36
+ health_check_interval : 10
35
37
service_address : " :3001"
36
38
builds :
37
39
path : " /builds"
Original file line number Diff line number Diff line change @@ -141,14 +141,33 @@ func (x *Codeflow) Start(events chan agent.Event) error {
141
141
return conn , err
142
142
}
143
143
144
- config .DialInfo .Timeout = time .Second * 3
144
+ config .DialInfo .Timeout = time .Second * viper . GetDuration ( "plugins.codeflow.mongodb.connection_timeout" )
145
145
}
146
146
147
147
db , err = bongo .Connect (config )
148
148
if err != nil {
149
149
log .Fatal (err )
150
150
}
151
151
152
+ // Try to reconnect if connection drops
153
+ go func (session * mgo.Session ) {
154
+ var err error
155
+ for {
156
+ err = session .Ping ()
157
+ if err != nil {
158
+ fmt .Println ("Lost connection to MongoDB!!" )
159
+ session .Refresh ()
160
+ err = session .Ping ()
161
+ if err == nil {
162
+ fmt .Println ("Reconnect to MongoDB successful." )
163
+ } else {
164
+ panic ("Reconnect to MongoDB failed!!" )
165
+ }
166
+ }
167
+ time .Sleep (time .Second * viper .GetDuration ("plugins.codeflow.mongodb.health_check_interval" ))
168
+ }
169
+ }(db .Session )
170
+
152
171
go x .Listen ()
153
172
154
173
log .Printf ("Started Codeflow service on %s\n " , x .ServiceAddress )
You can’t perform that action at this time.
0 commit comments