Skip to content

Commit

Permalink
quick fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
NorseGaud committed Dec 12, 2024
1 parent 680f075 commit 322c472
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 66 deletions.
14 changes: 8 additions & 6 deletions internal/github/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/gofri/go-github-ratelimit/github_ratelimit"
"github.com/google/go-github/v66/github"
"github.com/veertuinc/anklet/internal/config"
"github.com/veertuinc/anklet/internal/logging"
"github.com/veertuinc/anklet/internal/metrics"
)

Expand Down Expand Up @@ -112,19 +111,22 @@ func ExecuteGitHubClientFunction[T any](pluginCtx context.Context, logger *slog.
defer cancel()
result, response, err := executeFunc()
if response != nil {
innerPluginCtx = logging.AppendCtx(innerPluginCtx, slog.Int("api_limit_remaining", response.Rate.Remaining))
innerPluginCtx = logging.AppendCtx(innerPluginCtx, slog.String("api_limit_reset_time", response.Rate.Reset.Time.Format(time.RFC3339)))
innerPluginCtx = logging.AppendCtx(innerPluginCtx, slog.Int("api_limit", response.Rate.Limit))
logger.DebugContext(pluginCtx,
"GitHub API rate limit",
"remaining", response.Rate.Remaining,
"reset", response.Rate.Reset.Time.Format(time.RFC3339),
"limit", response.Rate.Limit,
)
if response.Rate.Remaining <= 10 { // handle primary rate limiting
sleepDuration := time.Until(response.Rate.Reset.Time) + time.Second // Adding a second to ensure we're past the reset time
logger.WarnContext(innerPluginCtx, "GitHub API rate limit exceeded, sleeping until reset")
metricsData, err := metrics.GetMetricsDataFromContext(pluginCtx)
if err != nil {
return innerPluginCtx, nil, nil, err
return pluginCtx, nil, nil, err
}
ctxPlugin, err := config.GetPluginFromContext(pluginCtx)
if err != nil {
return innerPluginCtx, nil, nil, err
return pluginCtx, nil, nil, err
}
metricsData.UpdatePlugin(pluginCtx, logger, metrics.PluginBase{
Name: ctxPlugin.Name,
Expand Down
7 changes: 5 additions & 2 deletions internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func Plugin(
firstPluginStarted chan bool,
metricsData *metrics.MetricsDataLock,
) (context.Context, error) {
var updatedPluginCtx context.Context
ctxPlugin, err := config.GetPluginFromContext(pluginCtx)
if err != nil {
return pluginCtx, err
Expand All @@ -42,7 +43,6 @@ func Plugin(
default:
close(firstPluginStarted)
}
var updatedPluginCtx context.Context
updatedPluginCtx, err = github.Run(workerCtx, pluginCtx, pluginCancel, logger, metricsData)
if err != nil {
return updatedPluginCtx, err
Expand All @@ -52,7 +52,10 @@ func Plugin(
}
// }
} else if ctxPlugin.Plugin == "github_receiver" {
github_receiver.Run(workerCtx, pluginCtx, pluginCancel, logger, firstPluginStarted, metricsData)
updatedPluginCtx, err = github_receiver.Run(workerCtx, pluginCtx, pluginCancel, logger, firstPluginStarted, metricsData)
if err != nil {
return updatedPluginCtx, err
}
} else {
return pluginCtx, fmt.Errorf("plugin not found")
}
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ func worker(
// get metrics from endpoint and update the main list
metrics.UpdatemetricsURLDBEntry(pluginCtx, parentLogger, metricsURL)
if workerCtx.Err() != nil || toRunOnce == "true" {
parentLogger.DebugContext(pluginCtx, "workerCtx.Err() != nil || toRunOnce == true")
pluginCancel()
break
}
Expand Down Expand Up @@ -491,7 +492,6 @@ func worker(
pluginCancel()
return
default:
// logging.DevContext(pluginCtx, "plugin for loop::default")
updatedPluginCtx, err := run.Plugin(
workerCtx,
pluginCtx,
Expand All @@ -516,8 +516,8 @@ func worker(
return
}
if workerCtx.Err() != nil || toRunOnce == "true" {
pluginCancel()
pluginLogger.WarnContext(updatedPluginCtx, shutDownMessage)
pluginCancel()
return
}
metricsData.SetStatus(updatedPluginCtx, pluginLogger, "idle")
Expand Down
1 change: 1 addition & 0 deletions plugins/handlers/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,7 @@ func Run(
// if not, then the runner registration failed
if !inProgressQueue {
logger.ErrorContext(pluginCtx, "waiting for runner registration timed out, will retry")
workflowJob.Conclusion = "failure" // support removeSelfHostedRunner
retryChannel <- true
return pluginCtx, nil
}
Expand Down
Loading

0 comments on commit 322c472

Please sign in to comment.