generated from ViBiOh/goweb
-
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.
feat(reminder): Adding reminder notifier for rb
Signed-off-by: Vincent Boutour <[email protected]>
- Loading branch information
Showing
14 changed files
with
187 additions
and
23 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
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,48 @@ | ||
apiVersion: helm.toolkit.fluxcd.io/v2beta1 | ||
kind: HelmRelease | ||
metadata: | ||
name: ketchup-remindeer | ||
namespace: default | ||
spec: | ||
interval: 120m | ||
chart: | ||
spec: | ||
chart: cron | ||
version: "0.0.19" | ||
sourceRef: | ||
kind: HelmRepository | ||
name: vibioh | ||
namespace: default | ||
interval: 120m | ||
install: | ||
crds: Skip | ||
maxHistory: 3 | ||
upgrade: | ||
remediation: | ||
retries: 3 | ||
rollback: | ||
cleanupOnFail: true | ||
values: | ||
nameOverride: ketchup-remindeer | ||
schedule: "0 16 * * 5" # manager is in UTC | ||
image: | ||
name: vibioh/ketchup | ||
tag: "202110251847" # {"$imagepolicy": "default:flux-ketchup-web:tag"} | ||
config: | ||
KETCHUP_DB_HOST: ketchup-db | ||
KETCHUP_DB_NAME: ketchup | ||
KETCHUP_DB_PORT: "80" | ||
KETCHUP_DB_USER: ketchup | ||
KETCHUP_LOGGER_JSON: "true" | ||
secrets: | ||
KETCHUP_DB_PASS: AgAw+m39PXVIRub8NNvEenJC1CuqSraj0//3FUlhc5NV4cLT0lr15v7oIsd+LyLD65iirArC+03AJ7NQ6HQ/G4a0ARY/mljIFw82+lvZXCF22KvUrJ9CXRY/4ugARluGNwNbUmxO+2frON7G8Ek4GzxyUQK54h2esRWf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++ZP8Bq1UyYApWcFQBcQdmJcqmuLL6dtKbzDtHTtPmE8aDqq2mSXhKX8j5TDmGM2uG9a/ijFV3IgUdTRZaYDM9LEqOctVpAcYgfTytaf3ADxOJKHVBpvRTMOsByzJ5TGruw8p2gcwSgOO1kHcNbR7n28mDHIkGYMevrdzvLKENMYCV/97rUrK7CSLFxia47ITe/q5ak8V94EyoklTESs+YT1jNF+EkNb7nL1r6axNiAnbQizQ8J4078dSofrFPzlDY6s0jmUOMt8q3I+d0MpkNAQ0vhuqXy0OBj4w3D2Lpi2tqEFJiQ8aXDH5j3IOr4MSHg27KL+hjfzxs0JVVFbMIAyOSBKZThoOls9DlmqNmBBegaEhPR2ehT1BpsMBbq | ||
containers: | ||
- name: job | ||
command: | ||
- /notifier | ||
- -notification | ||
- "reminder" | ||
resources: | ||
limits: | ||
memory: 128Mi |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
|
@@ -88,8 +88,8 @@ func (a App) Notify(ctx context.Context) error { | |
return fmt.Errorf("unable to get ketchup to notify: %w", err) | ||
} | ||
|
||
if err := a.sendNotification(userCtx, ketchupsToNotify); err != nil { | ||
return err | ||
if err := a.sendNotification(userCtx, "ketchup", ketchupsToNotify); err != nil { | ||
return fmt.Errorf("unable to send notification: %s", err) | ||
} | ||
|
||
if len(a.pushURL) != 0 { | ||
|
@@ -161,7 +161,7 @@ func (a App) getKetchupToNotify(ctx context.Context, releases []model.Release) ( | |
} | ||
|
||
logger.Info("%d weekly ketchups to notify", len(weeklyKetchups)) | ||
a.addWeeklyKetchups(weeklyKetchups, userToNotify) | ||
a.groupKetchupsToUsers(weeklyKetchups, userToNotify) | ||
} | ||
|
||
logger.Info("%d users to notify", len(userToNotify)) | ||
|
@@ -207,7 +207,7 @@ func (a App) syncReleasesByUser(releases []model.Release, ketchups []model.Ketch | |
return usersToNotify | ||
} | ||
|
||
func (a App) addWeeklyKetchups(ketchups []model.Ketchup, usersToNotify map[model.User][]model.Release) { | ||
func (a App) groupKetchupsToUsers(ketchups []model.Ketchup, usersToNotify map[model.User][]model.Release) { | ||
for _, ketchup := range ketchups { | ||
ketchupVersion, err := semver.Parse(ketchup.Version) | ||
if err != nil { | ||
|
@@ -240,7 +240,7 @@ func (a App) handleKetchupNotification(ketchup model.Ketchup, version string) { | |
} | ||
} | ||
|
||
func (a App) sendNotification(ctx context.Context, ketchupToNotify map[model.User][]model.Release) error { | ||
func (a App) sendNotification(ctx context.Context, template string, ketchupToNotify map[model.User][]model.Release) error { | ||
if len(ketchupToNotify) == 0 { | ||
return nil | ||
} | ||
|
@@ -259,7 +259,7 @@ func (a App) sendNotification(ctx context.Context, ketchupToNotify map[model.Use | |
"releases": releases, | ||
} | ||
|
||
mr := mailerModel.NewMailRequest().Template("ketchup").From("[email protected]").As("Ketchup").To(user.Email).Data(payload) | ||
mr := mailerModel.NewMailRequest().Template(template).From("[email protected]").As("Ketchup").To(user.Email).Data(payload) | ||
subject := fmt.Sprintf("Ketchup - %d new release", len(releases)) | ||
if len(releases) > 1 { | ||
subject += "s" | ||
|
@@ -273,3 +273,31 @@ func (a App) sendNotification(ctx context.Context, ketchupToNotify map[model.Use | |
|
||
return nil | ||
} | ||
|
||
// Remind users for new ketchup | ||
func (a App) Remind(ctx context.Context) error { | ||
userCtx := authModel.StoreUser(ctx, authModel.NewUser(a.loginID, "scheduler")) | ||
|
||
usersToRemind, err := a.userService.ListReminderUsers(userCtx) | ||
if err != nil { | ||
return fmt.Errorf("unable to get reminder users: %s", err) | ||
} | ||
|
||
remindKetchups, err := a.ketchupService.ListOutdatedByFrequency(userCtx, model.Daily, usersToRemind...) | ||
if err != nil { | ||
return fmt.Errorf("unable to get daily ketchups to remind: %s", err) | ||
} | ||
|
||
if len(remindKetchups) == 0 { | ||
return nil | ||
} | ||
|
||
usersToNotify := make(map[model.User][]model.Release) | ||
a.groupKetchupsToUsers(remindKetchups, usersToNotify) | ||
|
||
if err := a.sendNotification(userCtx, "ketchup_remind", usersToNotify); err != nil { | ||
return fmt.Errorf("unable to send remind notification: %s", err) | ||
} | ||
|
||
return nil | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE ketchup.user | ||
ADD COLUMN reminder BOOL NOT NULL DEFAULT FALSE; |