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

Rebuild Config on Server Restart #2076

Merged

Conversation

krishnaglick
Copy link
Collaborator

Adding rebuild config method. Calling rebuild config method on server restart.

Copy link
Member

@evantahler evantahler left a comment

Choose a reason for hiding this comment

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

This is probably important to test.

Here's a potential path forward:

  1. set a config with an ENV (like PORT=12345)
  2. startup the test like normal
    const actionhero = new Process();
    beforeAll(async () => await actionhero.start());
    afterAll(async () => await actionhero.stop());
  3. test that the config is what you expect (config.web.port === 12345)
  4. change the ENV in the test
  5. assert that the config is the old value
  6. reboot the server (process.restart)
  7. assert that the config is the new value

Comment on lines +12 to +18
it("updates config on 'restart'", () => {
const port = "2020";
process.env.PORT = port;
expect(config.web.port).not.toBe(port);
rebuildConfig();
expect(config.web.port).toBe(port);
});
Copy link
Member

Choose a reason for hiding this comment

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

👍

Comment on lines +234 to +242
export let config = buildConfig();
export const rebuildConfig = () => {
recalculateEnv();
recalculateActionheroVersion();
recalcuateId();
recalculateProjectRoot();
recalculateIsTypescript();
config = buildConfig();
};
Copy link
Member

Choose a reason for hiding this comment

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

This is a great pattern!

@evantahler evantahler merged commit b8f6bbc into actionhero:main Jan 10, 2022
@evantahler evantahler added the enhancement New feature or request label Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants