Problem/Motivation
A frontend that registers its own preview target can't say how long the target lasts, or remove it when it stops. A short-lived frontend, such as a tunnel or a branch build, leaves its target behind. The target stays in the Frontend picker for a day, then sits in the Inactive targets group until cron deletes it 30 days later.
Proposed resolution
- A PATCH to
/api/consumer-node-preview/targetstakes an optionalexpires_inon the target, in seconds. The target stores anexpirestime: the request time plusexpires_in, capped at the Delete after setting. - Once that time comes, the target leaves the Frontend picker, and a preview doesn't get a token for it. Cron then deletes it.
- Each PATCH sets a new time. A PATCH without
expires_inleaves the target with none, under the site's own limits as before. - A DELETE with
{"target": {"label": "..."}}removes the target with that label, with the same access checks as PATCH. A label that no target has changes nothing, so a frontend can repeat the request when it shuts down. consumer_node_preview_update_10001()adds theexpirescolumn to a 1.0.0-beta1 site. Drupal won't change a field's columns while it holds data, which a site with registered targets does. So the update adds the column in place and records the new schema, and the targets stay as they were.
Remaining tasks
- Review the merge request.
User interface changes
The Registered targets help text on the Preview tab says a frontend can give its target an earlier expiry of its own.
API changes
The targets endpoint accepts expires_in on PATCH, and a new DELETE method. Every answer lists each target's expires. PreviewTargetsProviderInterface::getTargets() and getTargetByKey() return expires too.
Data model changes
The preview_targets field gains an expires property and column, with an update for existing sites.
Issue fork consumer_node_preview-3636710
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
deciphered