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: cron removed on module change #3512

Merged
merged 2 commits into from
Nov 26, 2024
Merged

fix: cron removed on module change #3512

merged 2 commits into from
Nov 26, 2024

Conversation

stuartwdouglas
Copy link
Collaborator

fixes #3503

This was referenced Nov 25, 2024
@stuartwdouglas stuartwdouglas force-pushed the stuartwdouglas/3503 branch 4 times, most recently from 69863ae to fc03977 Compare November 25, 2024 21:07
@alecthomas
Copy link
Collaborator

Can you describe the actual change here? Or preferably, add comments to the PR. The code doesn't make sense to me on the face of it, but that's probably because I don't understand the problem.

@stuartwdouglas
Copy link
Collaborator Author

stuartwdouglas commented Nov 25, 2024

I added some comments. Basically you see the 'added' message for the new deployment before you see the 'removed' message. The code the way it was would end up deleting a modules cron jobs when the old module was removed.

@@ -78,6 +78,7 @@ func run(ctx context.Context, verbClient CallClient, changes chan *ftlv1.PullSch
logger := log.FromContext(ctx).Scope("cron")
// Map of cron jobs for each module.
cronJobs := map[string][]cronJob{}
currentDeploymentForModule := map[string]string{}
Copy link
Collaborator

Choose a reason for hiding this comment

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

What I don't understand is that it looks like keys are never removed from this map?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oops, that was an oversight, fixed. It would not have caused any actual issues in practice, unless you added and removed a huge number of modules.

switch resp.ChangeType {
case ftlv1.DeploymentChangeType_DEPLOYMENT_REMOVED:
// We see the new state of the module before we see the removed deployment.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah I see, that makes sense. Though if it's immediately ADDED, this shouldn't actually stop cron jobs from working as the ticket describes right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is ADDED then REMOVED, so we first get a message with the new cron schema, then get a message that the old one is removed. With the code the way it currently is all the cron jobs after the first deployment basically get removed immediately.

Copy link
Collaborator

@alecthomas alecthomas left a comment

Choose a reason for hiding this comment

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

We should fix the underlying issue and reverse the order of the updates, rather than add hacks to work around it.

@stuartwdouglas
Copy link
Collaborator Author

The order of the updates is correct though, both deployments are running for a while for rolling deployments, and canaries will only make this worse.

@stuartwdouglas stuartwdouglas requested a review from a team as a code owner November 26, 2024 01:49
@stuartwdouglas stuartwdouglas requested review from wesbillman and removed request for a team November 26, 2024 01:49
@@ -100,13 +100,18 @@ func Start(ctx context.Context, config Config, pullSchemaClient PullSchemaClient
newState.protoSchema.Modules = append(newState.protoSchema.Modules, resp.Schema)
}
} else if existing != nil {
// We see the new state of the module before we see the removed deployment.
// We only want to actually remove if it was not replaced by a new deployment.
if !resp.ModuleRemoved {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah nice.

@stuartwdouglas stuartwdouglas merged commit 8b511fe into main Nov 26, 2024
93 checks passed
@stuartwdouglas stuartwdouglas deleted the stuartwdouglas/3503 branch November 26, 2024 04:26
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.

cronjobs fail to trigger if a module is redeployed/updated
2 participants