improved tgsettle messages + storage fixes
This commit is contained in:
@@ -145,7 +145,7 @@ func (s *Scheduler) hydrateTimers(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
for _, record := range scheduled {
|
||||
s.TrackScheduled(record)
|
||||
s.TrackScheduled(&record)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,17 +200,53 @@ func (s *Scheduler) executeAndNotifyByID(ctx context.Context, requestID string)
|
||||
s.logger.Warn("Failed to execute treasury request", zap.Error(err), zap.String("request_id", requestID))
|
||||
return
|
||||
}
|
||||
if result == nil || result.Request == nil || s.notify == nil {
|
||||
if result == nil || result.Request == nil {
|
||||
s.logger.Debug("Treasury execution produced no result", zap.String("request_id", requestID))
|
||||
return
|
||||
}
|
||||
if s.notify == nil {
|
||||
s.logger.Warn("Treasury execution notifier is unavailable", zap.String("request_id", requestID))
|
||||
return
|
||||
}
|
||||
|
||||
text := executionMessage(result)
|
||||
if strings.TrimSpace(text) == "" {
|
||||
s.logger.Debug("Treasury execution result has no notification text",
|
||||
zap.String("request_id", strings.TrimSpace(result.Request.RequestID)),
|
||||
zap.String("status", strings.TrimSpace(string(result.Request.Status))))
|
||||
return
|
||||
}
|
||||
if err := s.notify(ctx, strings.TrimSpace(result.Request.ChatID), text); err != nil {
|
||||
s.logger.Warn("Failed to notify treasury execution result", zap.Error(err), zap.String("request_id", strings.TrimSpace(result.Request.RequestID)))
|
||||
chatID := strings.TrimSpace(result.Request.ChatID)
|
||||
if chatID == "" {
|
||||
s.logger.Warn("Treasury execution notification skipped: empty chat_id",
|
||||
zap.String("request_id", strings.TrimSpace(result.Request.RequestID)))
|
||||
return
|
||||
}
|
||||
|
||||
s.logger.Info("Sending treasury execution notification",
|
||||
zap.String("request_id", strings.TrimSpace(result.Request.RequestID)),
|
||||
zap.String("chat_id", chatID),
|
||||
zap.String("status", strings.TrimSpace(string(result.Request.Status))))
|
||||
|
||||
notifyCtx := context.Background()
|
||||
if ctx != nil {
|
||||
notifyCtx = ctx
|
||||
}
|
||||
notifyCtx, notifyCancel := context.WithTimeout(notifyCtx, 15*time.Second)
|
||||
defer notifyCancel()
|
||||
|
||||
if err := s.notify(notifyCtx, chatID, text); err != nil {
|
||||
s.logger.Warn("Failed to notify treasury execution result",
|
||||
zap.Error(err),
|
||||
zap.String("request_id", strings.TrimSpace(result.Request.RequestID)),
|
||||
zap.String("chat_id", chatID),
|
||||
zap.String("status", strings.TrimSpace(string(result.Request.Status))))
|
||||
return
|
||||
}
|
||||
s.logger.Info("Treasury execution notification sent",
|
||||
zap.String("request_id", strings.TrimSpace(result.Request.RequestID)),
|
||||
zap.String("chat_id", chatID),
|
||||
zap.String("status", strings.TrimSpace(string(result.Request.Status))))
|
||||
}
|
||||
|
||||
func executionMessage(result *ExecutionResult) string {
|
||||
@@ -237,7 +273,7 @@ func executionMessage(result *ExecutionResult) string {
|
||||
}
|
||||
}
|
||||
return op + " completed.\n\n" +
|
||||
"Account: " + strings.TrimSpace(request.LedgerAccountID) + "\n" +
|
||||
"Account: " + requestAccountCode(request) + "\n" +
|
||||
"Amount: " + sign + strings.TrimSpace(request.Amount) + " " + strings.TrimSpace(request.Currency) + "\n" +
|
||||
"New balance: " + balanceAmount + " " + balanceCurrency + "\n\n" +
|
||||
"Reference: " + strings.TrimSpace(request.RequestID)
|
||||
@@ -250,7 +286,7 @@ func executionMessage(result *ExecutionResult) string {
|
||||
reason = "Unknown error."
|
||||
}
|
||||
return "Execution failed.\n\n" +
|
||||
"Account: " + strings.TrimSpace(request.LedgerAccountID) + "\n" +
|
||||
"Account: " + requestAccountCode(request) + "\n" +
|
||||
"Amount: " + strings.TrimSpace(request.Amount) + " " + strings.TrimSpace(request.Currency) + "\n" +
|
||||
"Status: FAILED\n\n" +
|
||||
"Reason:\n" + reason + "\n\n" +
|
||||
@@ -259,3 +295,13 @@ func executionMessage(result *ExecutionResult) string {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func requestAccountCode(request *storagemodel.TreasuryRequest) string {
|
||||
if request == nil {
|
||||
return ""
|
||||
}
|
||||
if code := strings.TrimSpace(request.LedgerAccountCode); code != "" {
|
||||
return code
|
||||
}
|
||||
return strings.TrimSpace(request.LedgerAccountID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user