CreateMonitor creates a new balance monitor. It starts a tracing span, applies precision to the monitor's condition value, and creates the monitor. It records relevant events and errors. Parameters: - ctx context.Context: The context for the operation. - monitor model.BalanceMonitor: The BalanceMon
(ctx context.Context, monitor model.BalanceMonitor)
| 340 | // - model.BalanceMonitor: The created BalanceMonitor model. |
| 341 | // - error: An error if the monitor could not be created. |
| 342 | func (l *LedgerForge) CreateMonitor(ctx context.Context, monitor model.BalanceMonitor) (model.BalanceMonitor, error) { |
| 343 | _, span := balanceTracer.Start(ctx, "CreateMonitor") |
| 344 | defer span.End() |
| 345 | |
| 346 | amount := int64(monitor.Condition.Value * monitor.Condition.Precision) // apply precision to value |
| 347 | amountBigInt := model.Int64ToBigInt(amount) |
| 348 | monitor.Condition.PreciseValue = amountBigInt |
| 349 | monitor, err := l.datasource.CreateMonitor(monitor) |
| 350 | if err != nil { |
| 351 | span.RecordError(err) |
| 352 | return model.BalanceMonitor{}, err |
| 353 | } |
| 354 | |
| 355 | _ = l.cache.Delete(ctx, "monitors:"+monitor.BalanceID) |
| 356 | |
| 357 | span.AddEvent("Monitor created", trace.WithAttributes(attribute.String("monitor.id", monitor.MonitorID))) |
| 358 | return monitor, nil |
| 359 | } |
| 360 | |
| 361 | // GetMonitorByID retrieves a balance monitor by its ID. |
| 362 | // It starts a tracing span, fetches the monitor, and records relevant events. |