riteshghorse commented on code in PR #26101: URL: https://github.com/apache/beam/pull/26101#discussion_r1178161580
########## sdks/go/pkg/beam/core/timers/timers.go: ########## @@ -0,0 +1,161 @@ +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package timers contains structs for setting pipeline timers. +package timers + +import ( + "reflect" + "time" + + "github.com/apache/beam/sdks/v2/go/pkg/beam/core/graph/mtime" +) + +var ( + // ProviderType represents the type of timer provider. + ProviderType = reflect.TypeOf((*Provider)(nil)).Elem() +) + +// TimeDomainEnum represents different time domains to set timer. +type TimeDomainEnum int32 + +const ( + // TimeDomainUnspecified represents unspecified time domain. + TimeDomainUnspecified TimeDomainEnum = 0 + // TimeDomainEventTime is time from the perspective of the data + TimeDomainEventTime TimeDomainEnum = 1 + // TimeDomainProcessingTime is time from the perspective of the + // execution of your pipeline + TimeDomainProcessingTime TimeDomainEnum = 2 +) + +// TimerMap holds timer information obtained from the pipeline. +type TimerMap struct { + Family string + Tag string + Clear bool + FireTimestamp, HoldTimestamp mtime.Time +} + +type timerConfig struct { + Tag string + HoldTimestamp mtime.Time +} + +type timerOptions func(*timerConfig) + +// WithTag sets the tag for the timer. +func WithTag(tag string) timerOptions { + return func(tm *timerConfig) { + tm.Tag = tag + } +} + +// WithOutputTimestamp sets the output timestamp for the timer. +func WithOutputTimestamp(outputTimestamp time.Time) timerOptions { + return func(tm *timerConfig) { + tm.HoldTimestamp = mtime.FromTime(outputTimestamp) + } +} + +// Provider represents a timer provider interface. +type Provider interface { + Set(t TimerMap) +} + +// PipelineTimer interface represents valid timer type. +type PipelineTimer interface { + TimerFamily() string + TimerDomain() TimeDomainEnum Review Comment: Done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
