Skip to content

Shutdown inside initialize does not result in shutdown #56

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

Closed
michnovka opened this issue Jun 17, 2024 · 2 comments
Closed

Shutdown inside initialize does not result in shutdown #56

michnovka opened this issue Jun 17, 2024 · 2 comments

Comments

@michnovka
Copy link
Contributor

My usecase relies on some complex initialization i the initialize() method, and if it fails, it requests shutdown through $this->shutdown();

But Ive noticed that even then the execute() method is called at least once.

My proposal is:

  1. add protected/public method isShutdownRequested(): bool (the property is now private, so no way to access this)
  2. if initialize() requests shutdown, do not call execute even once.

WDYT?

@mac-cain13
Copy link
Owner

Think both proposals are good ideas that help with the use case you describe.

I think it would be good to make two adjustments:

  1. Add a protected method you describe so you're able to check whether a shutdown was requested. This makes it possible to abort longer running jobs at a point where you can control it. (However I still would recommend to make the iterations as small as possible, this can come in handy right before or after you access something over the network for example.)
  2. It's weird an iteration is executed after you've requested a shutdown, so I think the do { } while-loop should be changed to a while loop that checks for a shutdown at beginning of the first iteration already.

Would you be able to create a PR for these changes? Happy to merge it in!

@michnovka
Copy link
Contributor Author

See #57

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