Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Randomize locking job schedule to prevent running into github rate limits #410

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading