Skip to content

Commit 61cb194

Browse files
authored
feat wait on quotqa exceeded so quotqa recovers (#153)
1 parent 977a375 commit 61cb194

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

services/getgroupsettings/core.go

+15
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import (
3939
pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1"
4040
)
4141

42+
const waitSecOnQuotaExceeded = 70
43+
4244
// Global structure for global variables to optimize the cloud function performances
4345
type Global struct {
4446
ctx context.Context
@@ -256,6 +258,19 @@ func EntryPoint(ctxEvent context.Context, PubSubMessage gps.PubSubMessage, globa
256258
if !feedMessageGroup.Deleted {
257259
groupSettings, err := global.groupsSettingsService.Groups.Get(feedMessageGroup.Asset.Resource.Email).Do()
258260
if err != nil {
261+
if strings.Contains(strings.ToLower(err.Error()), "quota") {
262+
log.Println(glo.Entry{
263+
MicroserviceName: global.microserviceName,
264+
InstanceName: global.instanceName,
265+
Environment: global.environment,
266+
Severity: "WARNING",
267+
Message: fmt.Sprintf("waiting_on_quota_exceeded"),
268+
Description: fmt.Sprintf("GetGroupSettings quota is gone, wait for %d seconds then retry", waitSecOnQuotaExceeded),
269+
TriggeringPubsubID: global.PubSubID,
270+
})
271+
time.Sleep(waitSecOnQuotaExceeded * time.Second)
272+
return err
273+
}
259274
log.Println(glo.Entry{
260275
MicroserviceName: global.microserviceName,
261276
InstanceName: global.instanceName,

services/listgroupmembers/core.go

+15
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import (
4040
admin "google.golang.org/api/admin/directory/v1"
4141
)
4242

43+
const waitSecOnQuotaExceeded = 70
44+
4345
// Global variable to deal with GroupsListCall Pages constraint: no possible to pass variable to the function in pages()
4446
// https://pkg.go.dev/google.golang.org/api/admin/directory/v1?tab=doc#GroupsListCall.Pages
4547
var ancestors []string
@@ -311,6 +313,19 @@ func EntryPoint(ctxEvent context.Context, PubSubMessage gps.PubSubMessage, globa
311313
// pages function except just the name of the callback function. Not an invocation of the function
312314
err = global.dirAdminService.Members.List(feedMessageGroup.Asset.Resource.Id).MaxResults(global.maxResultsPerPage).Pages(ctx, browseMembers)
313315
if err != nil {
316+
if strings.Contains(strings.ToLower(err.Error()), "quota") {
317+
log.Println(glo.Entry{
318+
MicroserviceName: global.microserviceName,
319+
InstanceName: global.instanceName,
320+
Environment: global.environment,
321+
Severity: "WARNING",
322+
Message: fmt.Sprintf("waiting_on_quota_exceeded"),
323+
Description: fmt.Sprintf("ListGroupMembers quota is gone, wait for %d seconds then retry", waitSecOnQuotaExceeded),
324+
TriggeringPubsubID: global.PubSubID,
325+
})
326+
time.Sleep(waitSecOnQuotaExceeded * time.Second)
327+
return err
328+
}
314329
log.Println(glo.Entry{
315330
MicroserviceName: global.microserviceName,
316331
InstanceName: global.instanceName,

services/listgroups/core.go

+15
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import (
3939
admin "google.golang.org/api/admin/directory/v1"
4040
)
4141

42+
const waitSecOnQuotaExceeded = 70
43+
4244
// Global variable to deal with GroupsListCall Pages constraint: no possible to pass variable to the function in pages()
4345
// https://pkg.go.dev/google.golang.org/api/admin/directory/v1?tab=doc#GroupsListCall.Pages
4446
var ctx context.Context
@@ -340,6 +342,19 @@ func EntryPoint(ctxEvent context.Context, PubSubMessage gps.PubSubMessage, globa
340342

341343
err = queryDirectory(settings.Domain, settings.EmailPrefix, global)
342344
if err != nil {
345+
if strings.Contains(strings.ToLower(err.Error()), "quota") {
346+
log.Println(glo.Entry{
347+
MicroserviceName: global.microserviceName,
348+
InstanceName: global.instanceName,
349+
Environment: global.environment,
350+
Severity: "WARNING",
351+
Message: fmt.Sprintf("waiting_on_quota_exceeded"),
352+
Description: fmt.Sprintf("ListGroup quota is gone, wait for %d seconds then retry", waitSecOnQuotaExceeded),
353+
TriggeringPubsubID: global.PubSubID,
354+
})
355+
time.Sleep(waitSecOnQuotaExceeded * time.Second)
356+
return err
357+
}
343358
log.Println(glo.Entry{
344359
MicroserviceName: global.microserviceName,
345360
InstanceName: global.instanceName,

0 commit comments

Comments
 (0)