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

Backfill targetted #1649

Merged
merged 18 commits into from
Oct 17, 2022
Merged

Backfill targetted #1649

merged 18 commits into from
Oct 17, 2022

Conversation

joshkay10
Copy link
Contributor

@joshkay10 joshkay10 commented Oct 7, 2022

What's in this PR?
During a targetted backfill reset the relevant cursors and status's in reposync table

Why
Stops use syncing extra stuff we don't want to or setting states out of sync !

@joshkay10 joshkay10 marked this pull request as ready for review October 10, 2022 03:22
@joshkay10 joshkay10 requested a review from a team as a code owner October 10, 2022 03:22
@@ -37,6 +38,7 @@ export class RepoSyncState extends Model {

get status(): TaskStatus {
const statuses = [this.pullStatus, this.branchStatus, this.commitStatus];
console.log(statuses);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh the horror!

Copy link
Contributor Author

@joshkay10 joshkay10 Oct 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What have i done! 😢

fullSyncStartTime = new Date().toISOString();
if (targetTasks && targetTasks.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (targetTasks?.length)

Comment on lines 33 to 41
} else {
await subscription.update({
totalNumberOfRepos: null,
repositoryCursor: null,
repositoryStatus: null
});
// Remove all state as we're starting anew
await RepoSyncState.deleteFromSubscription(subscription);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic isn't correct. It's not just for a full backfill, but we want the ability to reset specific things for partial as well.

Hm... maybe we want to stop using the concept of 'full' or 'partial' and just make it "what do you want to reset before I send this backfill message to the queue"..

@@ -0,0 +1,54 @@
import { Request, Response } from "express";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change in here, just lifted from sync-utils and dumped

Comment on lines 63 to 78
const updateTasks = {};
targetTasks.forEach(task => {
if (syncType === "full") {
updateTasks[`${task}Cursor`] = null;
}
updateTasks[`${task}Status`] = null;
});

return RepoSyncState.update({
repoUpdatedAt: null,
...updateTasks
}, {
where: {
subscriptionId: subscription.id
}
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This completely forgets the repository task that's on subscription model (not reposyncstate), but also, it will also try to update repositoryStatus which doesn't exist on RepoSyncState and I think will error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohhh ok, i thought it was on the reposyncstate, but that make sense since its a higher level. copy that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to split this up into extra functions, especially since they have duplicate code in it. just a simple if statement for repository task should do

return;
}

const subscriptionTasks = targetTasks.find(task => task === "repository");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't you mean filter? or I guess you could change it to hasRepositoryTask = targetTasks.includes("repository");

@@ -49,6 +54,57 @@ export async function findOrStartSync(
}, 0, logger);
}

type subscriptionUpdateTasks = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Types should always start capitalized

updateSubscriptionTasks.repositoryStatus = null;
}

await subscription.update({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should only be called in the if statement above. You don't need to call this when there's nothing to update.
You also don't need to use the spread operator when it's the only key in the object, just use updateSubscriptionTasks as the update object.

const subscriptionTasks = targetTasks.find(task => task === "repository");
const repoSyncTasks = targetTasks.filter(task => task !== "repository");
const updateRepoSyncTasks = {};
const updateSubscriptionTasks: subscriptionUpdateTasks = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probbly move this in the if statement below and start it with the default key repositoryStatus: null

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

Successfully merging this pull request may close these issues.

None yet

2 participants