53200cbc0d
Nuevas funciones Go con tests en tres dominios: - core: parse_cron_expr, next_cron_time, join_by_key, validate_struct_fields + tipo CronSchedule - datascience: pivot (tabla dinámica), diff_entities (comparación de entidades) - infra: http_get_json, http_post_json, http_download_file, cache_to_sqlite, cron_ticker Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
46 lines
1.7 KiB
Markdown
46 lines
1.7 KiB
Markdown
---
|
|
name: cron_ticker
|
|
kind: function
|
|
lang: go
|
|
domain: infra
|
|
version: "1.0.0"
|
|
purity: impure
|
|
signature: "func CronTicker(schedule CronTickerSchedule, ctx context.Context) <-chan time.Time"
|
|
description: "Crea un channel que emite time.Time en cada tick del cron schedule. Usa time.NewTimer internamente, recalculando el proximo tick tras cada emision. El channel se cierra al cancelar el context. Incluye CronTickerSchedule (reflejo local de CronSchedule para evitar dependencia cross-package)."
|
|
tags: [cron, scheduling, ticker, channel, goroutine, concurrency, impure]
|
|
uses_functions: [parse_cron_expr_go_core, next_cron_time_go_core]
|
|
uses_types: [cron_schedule_go_core]
|
|
returns: []
|
|
returns_optional: false
|
|
error_type: "error_go_core"
|
|
imports: [context, time]
|
|
tested: true
|
|
tests:
|
|
- "context cancel cierra el channel"
|
|
- "ticker emite al llegar el momento del schedule"
|
|
test_file_path: "functions/infra/cron_ticker_test.go"
|
|
file_path: "functions/infra/cron_ticker.go"
|
|
---
|
|
|
|
## Ejemplo
|
|
|
|
```go
|
|
sched := CronTickerSchedule{
|
|
Minute: []int{0, 15, 30, 45},
|
|
Hour: intRange(0, 23),
|
|
DayOfMonth: intRange(1, 31),
|
|
Month: intRange(1, 12),
|
|
DayOfWeek: intRange(0, 6),
|
|
}
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
for tick := range CronTicker(sched, ctx) {
|
|
fmt.Println("tick:", tick)
|
|
}
|
|
```
|
|
|
|
## Notas
|
|
|
|
Funcion impura: lanza una goroutine, usa time.NewTimer y context. El tipo CronTickerSchedule es un reflejo local de core.CronSchedule para evitar imports cross-package entre dominios Go. En uso real, convertir el resultado de core.ParseCronExpr manualmente. El channel tiene buffer de 1 para evitar bloqueos si el consumidor es lento; los ticks extras se descartan.
|