nomadcode/services/core/internal/notification/service.go
toki 4b6951cfa8 feat: notification 및 workflow 기능 개선
- notification 서비스 테스트 추가
- workflow lifecycle 관리 구현
- config, scheduler, workflow 서비스 개선
2026-05-24 19:36:43 +09:00

51 lines
1.1 KiB
Go

package notification
import (
"context"
"log/slog"
"github.com/nomadcode/nomadcode-core/internal/adapters/mattermost"
)
type Service struct {
mattermost *mattermost.Client
logger *slog.Logger
}
func NewService(mattermostClient *mattermost.Client, logger *slog.Logger) *Service {
return &Service{
mattermost: mattermostClient,
logger: logger,
}
}
func (s *Service) NotifyTaskCompleted(ctx context.Context, input TaskNotification) error {
return s.NotifyTaskEvent(ctx, TaskEvent{
Type: TaskEventCompleted,
TaskID: input.TaskID,
Title: input.Title,
Status: input.Status,
Message: input.Message,
})
}
func (s *Service) NotifyTaskEvent(ctx context.Context, input TaskEvent) error {
if s.logger != nil {
s.logger.Info("task event notification requested", "type", input.Type, "task_id", input.TaskID)
}
if input.Type != TaskEventCompleted {
return nil
}
if s.mattermost == nil {
return nil
}
return s.mattermost.SendTaskNotification(ctx, mattermost.TaskNotificationInput{
TaskID: input.TaskID,
Title: input.Title,
Status: input.Status,
Message: input.Message,
})
}