-
Notifications
You must be signed in to change notification settings - Fork 8
/
bqtail.go
45 lines (40 loc) · 1.03 KB
/
bqtail.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package bqtail
import (
"cloud.google.com/go/functions/metadata"
"context"
"errors"
"github.com/viant/bqtail/shared"
"github.com/viant/bqtail/tail"
"github.com/viant/bqtail/tail/contract"
_ "github.com/GoogleCloudPlatform/functions-framework-go/funcframework"
)
const maxStackDriver = 265 * 1024
//BqTail storage trigger background cloud function entry point
func BqTail(ctx context.Context, event contract.GSEvent) (err error) {
meta, err := metadata.FromContext(ctx)
if err != nil {
return err
}
request := &contract.Request{
EventID: meta.EventID,
SourceURL: event.URL(),
Started: meta.Timestamp,
}
_, err = handleTailEvent(ctx, request)
if err != nil {
return err
}
return nil
}
func handleTailEvent(ctx context.Context, request *contract.Request) (*contract.Response, error) {
service, err := tail.Singleton(ctx)
if err != nil {
return nil, err
}
response := service.Tail(ctx, request)
shared.LogLn(response)
if response.Error != "" {
return response, errors.New(response.Error)
}
return response, nil
}