MCPcopy Index your code
hub / github.com/devaccuracy/ledgerforge / CreateMonitor

Method CreateMonitor

balance.go:342–359  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

340// - model.BalanceMonitor: The created BalanceMonitor model.
341// - error: An error if the monitor could not be created.
342func (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.

Callers 1

TestCreateMonitorFunction · 0.95

Calls 4

Int64ToBigIntFunction · 0.92
CreateMonitorMethod · 0.65
DeleteMethod · 0.65
StartMethod · 0.45

Tested by 1

TestCreateMonitorFunction · 0.76