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: move application logic to service #3846

Merged
merged 5 commits into from
May 23, 2023

Conversation

kwasniew
Copy link
Contributor

@kwasniew kwasniew commented May 23, 2023

About the changes

Fixing problem that manifested in change requests application but the root cause was in the toggle controller:

  • moving application logic to a service from a controller since it's easier to reuse from a service
  • adding transaction boundaries around update of strategies so that strategy change and disabling of the toggle either both succeed of both fail but never leave the system in the inconsistent state

Important files

Discussion points

@vercel
Copy link

vercel bot commented May 23, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
unleash-monorepo-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 23, 2023 2:22pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) May 23, 2023 2:22pm


const env = feature.environments.find((e) => e.name === environment);
const hasOnlyDisabledStrategies = env!.strategies.every(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the ! to ignore type system in production code is not a good idea. I replaced it with env?. because I managed to get null pointer here

{ environment, projectId, featureName },
userName,
req.user,
const updatedStrategy = await this.startTransaction(async (tx) =>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

updating strategy and toggle should be part of one DB transaction

@@ -510,6 +510,29 @@ class FeatureToggleService {
return this.unprotectedUpdateStrategy(id, updates, context, userName);
}

async optionallyDisableFeature(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was previously in a controller but it means that change requests calling service methods don't have access to full functionality. Overall controller shouldn't orchestrate application logic, application service should do it.

@@ -180,7 +183,7 @@ const createTestSegments = async () => {

beforeAll(async () => {
db = await dbInit('segments', getLogger);
app = await setupApp(db.stores);
app = await setupAppWithCustomConfig(db.stores, {}, db.rawDatabase);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we need to pass raw database because otherwise transactions don't work in this test

);
}
}

async unprotectedUpdateStrategy(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this method is called by change requests apply method

Copy link
Contributor

@andreas-unleash andreas-unleash left a comment

Choose a reason for hiding this comment

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

LGTM

@kwasniew kwasniew merged commit 1dba9d0 into main May 23, 2023
11 of 14 checks passed
@kwasniew kwasniew deleted the disabling-last-strategy-disables-toggle branch May 23, 2023 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants