mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-06 04:09:40 -06:00
feat: Add cli command to trigger grouped emails
This commit is contained in:
@@ -15,6 +15,7 @@ func GetCommands(cfg *config.Config) cli.Commands {
|
||||
Server(cfg),
|
||||
|
||||
// interaction with this service
|
||||
SendEmail(cfg),
|
||||
|
||||
// infos about this service
|
||||
Health(cfg),
|
||||
|
||||
57
services/notifications/pkg/command/send_email.go
Normal file
57
services/notifications/pkg/command/send_email.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"github.com/cs3org/reva/v2/pkg/events"
|
||||
"github.com/cs3org/reva/v2/pkg/events/stream"
|
||||
"github.com/owncloud/ocis/v2/services/notifications/pkg/config"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// SendEmail triggers the sending of grouped email notifications for daily or weekly emails.
|
||||
func SendEmail(cfg *config.Config) *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "send-email",
|
||||
Usage: "Send grouped email notifications with daily or weekly interval. Specify at least one of the flags '--daily' or '--weekly'.",
|
||||
Flags: []cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Name: "daily",
|
||||
Aliases: []string{"d"},
|
||||
Usage: "Sends grouped daily email notifications.",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "weekly",
|
||||
Aliases: []string{"w"},
|
||||
Usage: "Sends grouped weekly email notifications.",
|
||||
},
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
daily := c.Bool("daily")
|
||||
weekly := c.Bool("weekly")
|
||||
if !daily && !weekly {
|
||||
return errors.New("at least one of '--daily' or '--weekly' must be set")
|
||||
}
|
||||
s, err := stream.NatsFromConfig(cfg.Service.Name, false, stream.NatsConfig(cfg.Notifications.Events))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if daily {
|
||||
err = events.Publish(c.Context, s, events.SendEmailsEvent{
|
||||
Interval: "daily",
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if weekly {
|
||||
err = events.Publish(c.Context, s, events.SendEmailsEvent{
|
||||
Interval: "weekly",
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user