Documentation ¶
Index ¶
Constants ¶
const ( EventTimeReached = "event_time_reached" EventCountReached = "event_count_reached" EventConditionScheme = "event_condition_scheme" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Trigger)
func WithCondition ¶
func WithCondition(c context.Context, f func(ctx context.Context, event string, elements ...interface{}) int) Option
WithCondition is more flexible than WithMaxTime and WithMaxCount, it provides a function to decide the batch count of elements by receiving the event push by Trigger. The param f is a function has three param
ctx is the same as WithCondition first param context.Context
event has three value, see more details from the comment above.
elements are batch that packed when the event happened.
The return is an int value, when event is EventTimeReached or EventCountReached, it's ignored, only when the event is EventConditionScheme, it means the count of elements need to pack for batch.
func WithMaxCount ¶
WithMaxCount sets the count, when elements in Trigger reach it, the Trigger will pack all elements in it to batch and send elements batch to receiver queue.
func WithMaxTime ¶
WithMaxTime sets a timer, when it's expired, elements in Trigger will be packed as batch and send elements batch to receiver queue.
type Trigger ¶
type Trigger struct {
// contains filtered or unexported fields
}
Trigger accepts element put, and work as a counter. When max_count, timer or condition reaches, it will do notify by the callback function. It's used in log or message collector scenes as usual. Logs and messages are put into the Trigger's queue, given a timer or max_count for trigger to pack the elements to a batch, and then send them in one request to the backend server.
func NewTrigger ¶
NewTrigger create the Trigger, the receiver param is the queue for receiving the batch elements which is return by trigger reached. Elements in receiver queue is type '[]interface{}'. Option provides trigger setting, such as max_time, max_count or condition defined by yourself. One option would be setting at least, all options could be set together yet. All methods of Trigger are thread-safe.
func (*Trigger) Flush ¶
func (this *Trigger) Flush()
Flush will do pack all elements in Trigger to batch manually.