mirror of
https://github.com/syumai/workers.git
synced 2025-03-11 01:39:11 +00:00
29 lines
615 B
Go
29 lines
615 B
Go
package cron
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"time"
|
|
|
|
"github.com/syumai/workers/internal/runtimecontext"
|
|
)
|
|
|
|
// Event represents information about the Cron that invoked this worker.
|
|
type Event struct {
|
|
Cron string
|
|
ScheduledTime time.Time
|
|
}
|
|
|
|
func NewEvent(ctx context.Context) (*Event, error) {
|
|
obj := runtimecontext.MustExtractTriggerObj(ctx)
|
|
if obj.IsUndefined() {
|
|
return nil, errors.New("event is null")
|
|
}
|
|
|
|
scheduledTimeVal := obj.Get("scheduledTime").Float()
|
|
return &Event{
|
|
Cron: obj.Get("cron").String(),
|
|
ScheduledTime: time.Unix(int64(scheduledTimeVal)/1000, 0).UTC(),
|
|
}, nil
|
|
}
|