Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
notifications-bot
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
archives
notifications-bot
Commits
c5d4b73a
Commit
c5d4b73a
authored
Feb 10, 2020
by
Jonah Husson
Browse files
Options
Downloads
Patches
Plain Diff
change how reconnecting to gateway works
parent
01c9b68f
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
cmd/root.go
+9
-4
9 additions, 4 deletions
cmd/root.go
notifications/notifications.go
+5
-19
5 additions, 19 deletions
notifications/notifications.go
notifications/notifications_test.go
+2
-4
2 additions, 4 deletions
notifications/notifications_test.go
with
16 additions
and
27 deletions
cmd/root.go
+
9
−
4
View file @
c5d4b73a
...
...
@@ -87,7 +87,7 @@ var rootCmd = &cobra.Command{
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"Failed to Create permissioning host: %+v"
,
err
)
}
Setup
:
ndf
,
err
:=
notifications
.
PollNdf
(
nil
,
impl
.
Comms
)
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"Failed to get NDF: %+v"
,
err
)
...
...
@@ -100,12 +100,17 @@ var rootCmd = &cobra.Command{
// Start notification loop
killChan
:=
make
(
chan
struct
{})
errChan
:=
make
(
chan
error
)
go
impl
.
RunNotificationLoop
(
viper
.
GetString
(
"firebaseCredentialsPath"
),
loopDelay
,
killChan
)
loopDelay
,
killChan
,
errChan
)
// Wait forever to prevent process from ending
select
{}
select
{
case
err
:=
<-
errChan
:
jww
.
ERROR
.
Println
(
err
)
goto
Setup
default
:
}
},
}
...
...
This diff is collapsed.
Click to expand it.
notifications/notifications.go
+
5
−
19
View file @
c5d4b73a
...
...
@@ -59,7 +59,7 @@ type NotificationComms interface {
// Main function for this repo accepts credentials and an impl
// loops continuously, polling for notifications and notifying the relevant users
func
(
nb
*
Impl
)
RunNotificationLoop
(
fbCreds
string
,
loopDuration
int
,
killChan
chan
struct
{})
{
func
(
nb
*
Impl
)
RunNotificationLoop
(
fbCreds
string
,
loopDuration
int
,
killChan
chan
struct
{}
,
errChan
chan
error
)
{
fc
:=
firebase
.
NewFirebaseComm
()
for
{
// Stop execution if killed by channel
...
...
@@ -71,13 +71,15 @@ func (nb *Impl) RunNotificationLoop(fbCreds string, loopDuration int, killChan c
UIDs
,
err
:=
nb
.
pollFunc
(
nb
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Failed to poll gateway for users to notify: %+v"
,
err
)
errChan
<-
errors
.
Errorf
(
"Failed to poll gateway for users to notify: %+v"
,
err
)
return
}
for
_
,
id
:=
range
UIDs
{
_
,
err
:=
nb
.
notifyFunc
(
id
,
fbCreds
,
fc
,
nb
.
Storage
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Failed to notify user with ID %+v: %+v"
,
id
,
err
)
errChan
<-
errors
.
Errorf
(
"Failed to notify user with ID %+v: %+v"
,
id
,
err
)
return
}
}
...
...
@@ -169,24 +171,8 @@ func notifyUser(uid string, serviceKeyPath string, fc *firebase.FirebaseComm, db
// pollForNotifications accepts a gateway host and a RequestInterface (a comms object)
// It retrieves a list of user ids to be notified from the gateway
func
pollForNotifications
(
nb
*
Impl
)
(
strings
[]
string
,
e
error
)
{
updateNdf
:=
func
()
error
{
ndf
,
err
:=
PollNdf
(
nil
,
nb
.
Comms
)
if
err
!=
nil
{
return
errors
.
Errorf
(
"Could not poll for new NDF: %+v"
,
err
)
}
err
=
nb
.
UpdateNdf
(
ndf
)
if
err
!=
nil
{
return
errors
.
Errorf
(
"Could not update ndf: %+v"
,
err
)
}
return
nil
}
h
,
ok
:=
nb
.
Comms
.
GetHost
(
"gw"
)
if
!
ok
{
err
:=
updateNdf
()
if
err
!=
nil
{
return
nil
,
errors
.
Errorf
(
"Could not find gateway host & failed to poll for new NDF: %+v"
,
err
)
}
return
nil
,
errors
.
New
(
"Could not find gateway host"
)
}
...
...
This diff is collapsed.
Click to expand it.
notifications/notifications_test.go
+
2
−
4
View file @
c5d4b73a
...
...
@@ -29,17 +29,15 @@ func TestRunNotificationLoop(t *testing.T) {
return
[]
string
{
"test1"
,
"test2"
},
nil
}
impl
.
notifyFunc
=
func
(
s3
string
,
s2
string
,
comm
*
firebase
.
FirebaseComm
,
storage
storage
.
Storage
)
(
s
string
,
e
error
)
{
if
s3
==
"test1"
{
return
""
,
errors
.
New
(
"Failed to notify"
)
}
return
"good"
,
nil
}
killChan
:=
make
(
chan
struct
{})
errChan
:=
make
(
chan
error
)
go
func
()
{
time
.
Sleep
(
10
*
time
.
Second
)
killChan
<-
struct
{}{}
}()
impl
.
RunNotificationLoop
(
""
,
3
,
killChan
)
impl
.
RunNotificationLoop
(
""
,
3
,
killChan
,
errChan
)
}
// Test notificationbot's notifyuser function
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment