-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #137 from Tibz-Dankan/refactor/dir-structure
Refactor/dir structure
- Loading branch information
Showing
26 changed files
with
154 additions
and
135 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,4 @@ | ||
cmd | ||
internal | ||
tests | ||
Makefile |
This file was deleted.
Oops, something went wrong.
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
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,7 @@ | ||
package publishers | ||
|
||
import "log" | ||
|
||
func InitEventPublishers() { | ||
log.Println("Initiating global event publishers...") | ||
} |
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,36 @@ | ||
package publishers | ||
|
||
import ( | ||
"log" | ||
"sync" | ||
|
||
"github.com/Tibz-Dankan/keep-active/internal/events" | ||
"github.com/Tibz-Dankan/keep-active/internal/models" | ||
) | ||
|
||
// Publishes all apps to the topic "makeRequest" | ||
// for the purposes of making requests to the apps. | ||
// This function must be called in a scheduler | ||
func PublishRequestEvent() { | ||
app := models.App{} | ||
|
||
apps, err := app.FindAll() | ||
if err != nil { | ||
log.Println("Error fetching apps:", err) | ||
return | ||
} | ||
|
||
if len(apps) == 0 { | ||
return | ||
} | ||
|
||
var wg sync.WaitGroup | ||
for _, app := range apps { | ||
wg.Add(1) | ||
go func(app models.App) { | ||
defer wg.Done() | ||
events.EB.Publish("makeRequest", app) | ||
}(app) | ||
} | ||
wg.Wait() | ||
} |
7 changes: 4 additions & 3 deletions
7
internal/event/permissions.go → internal/events/subscribers/permissions.go
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
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,30 @@ | ||
package subscribers | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/Tibz-Dankan/keep-active/internal/events" | ||
"github.com/Tibz-Dankan/keep-active/internal/models" | ||
"github.com/Tibz-Dankan/keep-active/internal/routes/request" | ||
) | ||
|
||
// Subscribes/listens to the topic "makeRequest" | ||
// and performs an http get request to each app | ||
// whose data has been received. | ||
func subscribeToRequestEvent() { | ||
appCh := make(chan events.DataEvent) | ||
events.EB.Subscribe("makeRequest", appCh) | ||
type App = models.App | ||
|
||
for { | ||
appEvent := <-appCh | ||
app, ok := appEvent.Data.(App) | ||
|
||
if !ok { | ||
log.Println("Interface does not hold type App") | ||
return | ||
} | ||
|
||
go request.MakeAppRequest(app) | ||
} | ||
} |
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,9 @@ | ||
package subscribers | ||
|
||
import "log" | ||
|
||
func InitEventSubscribers() { | ||
log.Println("Initiating global event subscribers...") | ||
go subscribeToRequestEvent() | ||
subscribeToPermissions() | ||
} |
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.