Problem/Motivation
Original issue: #1891980: Add Service termination API to reliable terminate/shut down services in the container
Proposed resolution
Remaining tasks
User interface changes
API changes
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | interdiff_2447365_12-14.txt | 670 bytes | jacobsanford |
| #14 | explain_destructableinterface-2447365-14.patch | 2.57 KB | jacobsanford |
| #12 | interdiff_2447365_9-12.txt | 687 bytes | jacobsanford |
| #12 | explain_destructableinterface-2447365-12.patch | 2.53 KB | jacobsanford |
| #9 | interdiff_2447365_6-9.txt | 555 bytes | jacobsanford |
Comments
Comment #1
dawehnerI guess this is the right component.
Comment #2
klausiAnd we should document where this interface is used, namely with the "needs_destruction" tag for services. I just had to reverse engineer that since searching for the interface name yielded no results and I wanted to know where the actual destruction happens.
Comment #3
klausiklausi opened a new pull request for this issue.
Comment #4
dawehnerNote: We have some form of standard for those kind of documentation: https://www.drupal.org/files/issues/document_service_tags-2417789-17.patch
Comment #5
jhodgdonGreat!
One small nitpick: in the core.api.php section of the patch:
I would take out "the". We usually just say "Foo implements BarInterface" not "Foo implements *the* BarInterface".
Other than that, looks good to me and if "the" is removed I'd be in favor of RTBC.
Regarding @service_tag, that has not been adopted yet. See
#2264047: [meta] Document service definition tags
Comment #6
klausiklausi pushed some commits to the pull request.
For an interdiff please see the list of recent commits.
Comment #7
dawehnerThe feedback from @jhodgdon got addressed,
For now this seems to be an improvement, so let's get it in.
Comment #8
webchickSo... these look like good improvements to make, but none of them actually does what the issue title states, which is explain why DestructableInterface is useful. :)
Can we add a thing under here like:
...or whatever the actual reason you'd implement this as a module developer is?
Comment #9
jacobsanfordAdded information requested in #8. Thanks for input!
I kept it terse and close to recommended text, but included a bit about rebuild/recreation due to use in caching or similar - not just termination.
Comment #10
jhodgdonHm. There seems to be some disagreement... In core.api.php we have:
Then in the interface, it says:
So in the core.api.php file, it indicates that destruct() is called at the end of the request, but in the interface, it kind of implies that it could get rebuilt or terminated before the request ends. This is confusing to me. How would it get rebuilt??!? It seems like all that happens is that the destruct() method gets called, which I think is not a rebuild, and it's at the very end of the request...
So it seems like really what this means is that if your service class can just get destroyed normally when the PHP class goes away (or using the usual PHP class desctructor method), you don't need this interface, but if you have some kind of cleanup to do, you need this, right? What would be an example?
Comment #11
jacobsanfordAt first look I assumed that it was both : extending DestructableInterface (and setting the tag) gave you a ready-baked way to destroy (and control what destruction meant with ::destruct()) at the end of the request, as well as offering a method to reinitialize it on demand if desired. I will admit I can now find no use of the latter in the API:
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!DestructableInterface.php/interface/DestructableInterface/8
And in fact 'destruct' doesn't even remotely imply reincarnation-like behavior. I think your confusion is valid, and agree that the documentation should only show the first case.
Comment #12
jacobsanfordEnclosed are discussed changes. Thanks for review!
Regards.
Comment #13
dawehnerWe should explain that those runs ideally after the response is sent.
Comment #14
jacobsanfordSure thing - thanks for review. Requested changes are attached.
Comment #15
klausiLooks good to me, thanks!
Comment #17
xjmThanks, this makes the purpose of the interface more clear. "The interface for services that need explicit destruction" was kind of intriguing and dramatic by itself. ;)
This issue only changes documentation, so per https://www.drupal.org/core/beta-changes, this can be completed any time during the Drupal 8 beta phase. Committed and pushed to 8.0.x (with credit for reviewers).