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

CronJob duplicates on Vercel #1029

Closed
markkkkas opened this issue Sep 1, 2022 · 6 comments
Closed

CronJob duplicates on Vercel #1029

markkkkas opened this issue Sep 1, 2022 · 6 comments

Comments

@markkkkas
Copy link

markkkkas commented Sep 1, 2022

Bug Report

Current Behavior
Currently I have one CronJob which works fine, but when i redeploy my "production" environment in Vercel, using documentation provided method I see duplicated CronJob in my ui.quirrel.dev webpage.
Is this behaviour expected, or "old" CronJob instances should be cleaned up after new deployment?

Input Code
Just regular CronJob

import { CronJob } from "quirrel/next";

export default CronJob(
  "api/customCron",
  async () => {
    // await ...
  }
)

Expected behavior/code
I expect that old CronJob instances should be deleted and only one is visible in ui.quirrel.dev webpage.

Environment

  • Quirrel version: 1.9.2
  • Node/npm version: node 16/pnpm 7.9.5
  • Nextjs 12.2
  • Vercel

Additional context/Screenshots
package.json

{
  "scripts": {
    "build:vercel": "next build && quirrel ci"
  }
}

CleanShot 2022-09-01 at 22 24 49

Thank you in advance!

@Skn0tt
Copy link
Member

Skn0tt commented Sep 13, 2022

quirrel ci is supposed to clean up old cronjobs, that's right. Here's the code:

public async updateCron(
tokenId: string,
{ baseUrl, crons, dryRun }: QueuesUpdateCronBody
) {
const deleted: string[] = [];
const queues = await this.queueRepo.get(tokenId);
const queuesOnSameDeployment = queues.filter((q) => q.startsWith(baseUrl));
if (!dryRun) {
await Promise.all(
crons.map(async ({ route, schedule, timezone }) => {
await this.enqueue(
tokenId,
`${config.withoutTrailingSlash(
baseUrl
)}/${config.withoutLeadingSlash(route)}`,
{
id: "@cron",
body: "null",
override: true,
repeat: { cron: schedule, cronTimezone: timezone },
}
);
})
);
}
const routesThatShouldPersist = crons
.map((c) => c.route)
.map(withoutWrappingSlashes);
await Promise.all(
queuesOnSameDeployment.map(async (queue) => {
const route = withoutWrappingSlashes(queue.slice(baseUrl.length));
const shouldPersist = routesThatShouldPersist.includes(route);
if (shouldPersist) {
return;
}
if (dryRun) {
const exists = await this.findById(tokenId, queue, "@cron");
if (exists) {
deleted.push(queue);
}
} else {
const result = await this.delete(tokenId, queue, "@cron");
if (result === "deleted") {
deleted.push(queue);
}
}
})
);
return { deleted };
}

Not sure what's causing this. Could you try to write up some a minimal reproduction steps that I can use to reproduce this issue? That'd make it a lot easier for me to help you on this.

@Skn0tt
Copy link
Member

Skn0tt commented Oct 18, 2022

Closing this, feel free to reopen.

@Skn0tt Skn0tt closed this as completed Oct 18, 2022
@markkkkas
Copy link
Author

markkkkas commented Nov 30, 2022

Hey @Skn0tt, sorry for late reply I cannot reopen, so im writing it here.

Im currently using this setup:

  1. Vercel for next.js app
  2. Self-hosted quirrel on netlify

Build command: "build:vercel": "next build && quirrel ci"

As you can see, quirrel tried to update cron jobs
image

And unfrotunately UI shows 2 jobs, which are actually executed 2 times, so if i rerun this, it will be 3 jobs, 4 jobs and etc...
image

image

image

@Skn0tt
Copy link
Member

Skn0tt commented Nov 30, 2022

Self-hosted quirrel on netlify

Could you elaborate on how you set that up? I'm not aware of any way of hosting the Quirrel app on Netlify, so it'd be very interesting to learn what you mean by this.

And unfrotunately UI shows 2 jobs,

I have the suspicion that these two jobs, which are seemingly to the same URL, share the same path but have different hosts. The UI only shows the path, but if you hover over it, the tooltip should show the full URL. My suspicion is that one is https://preview-a.vercel.app/api/populate-patients/cron and the other is https://preview-b.vercel.app/api/populate-patients/cron, or something similar. That breaks Quirrel's cron deduplication.
If that's the case, check if the QUIRREL_BASE_URL variable is the same for all your deployments. quirrel ci relies on that to properly deduplicate.

@markkkkas
Copy link
Author

@Skn0tt
Sorry for confusing you, it's not Netlify, its fly.io. I followed this approach https://dev.to/remixtape/self-hosting-quirrel-5af7

Regarding the QUIRREL_BASE_URL looks like im missing it! Ill try to add it and then will try to redeploy.

@markkkkas
Copy link
Author

@Skn0tt looks like that we managed to fix it! Thank you very much for support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants