Skip to content

Commit

Permalink
fix: Randomize locking job schedule to prevent running into github ra…
Browse files Browse the repository at this point in the history
…te limits (#410)

<!--

Unless this is a very simple 1-line-of-code change, please create a new
issue describing the change you're proposing first, then link to it from
this PR.

Read more about our process in our contributing guide:
https://github.com/cdktf/.github/blob/main/CONTRIBUTING.md

-->

### Description

As seen in the following images, we seem to be running into a secondary
rate limit when we try to lock issues within our provider repositories.

<img width="1671" alt="image"
src="https://github.com/cdktf/cdktf-provider-project/assets/573531/6fde8b66-653e-4cab-8231-222dae3f73d0">

<img width="645" alt="image"
src="https://github.com/cdktf/cdktf-provider-project/assets/573531/588858f8-0546-4c3b-b9f4-611626c7ef2d">

<img width="740" alt="image"
src="https://github.com/cdktf/cdktf-provider-project/assets/573531/0caa4347-2fbe-427e-b57e-88a7bd121d7c">

This PR tries to use a hash of the project name to generate a somewhat
unique cron schedule across all our repositories. I have to say that I
haven't really thought too hard about this, so if you feel there are
problems in my approach, please let me know.
  • Loading branch information
mutahhir authored Apr 2, 2024
1 parent 077db6e commit 7b8907d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion src/lock-issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: MPL-2.0
*/

import { createHash } from "crypto";
import { javascript } from "projen";
import { JobPermission } from "projen/lib/github/workflows-model";

Expand All @@ -17,8 +18,14 @@ export class LockIssues {

if (!workflow) throw new Error("no workflow defined");

const projectNameHash = createHash("md5")
.update(project.name)
.digest("hex");
const scheduleHour = parseInt(projectNameHash.slice(0, 2), 16) % 24;
const scheduleMinute = parseInt(projectNameHash.slice(2, 4), 16) % 24;

workflow.on({
schedule: [{ cron: "20 2 * * *" }],
schedule: [{ cron: `${scheduleHour} ${scheduleMinute} * * *` }],
});

workflow.addJob("lock", {
Expand Down
10 changes: 5 additions & 5 deletions test/__snapshots__/index.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7b8907d

Please sign in to comment.