Skip to content

[Feature]: A plugin command's cube.reduce on a STAC collection runs off the frame, and the command runs again when it lands #3183

Done

Description

@elpidioassinaturas

The problem

A plugin command that calls cube.reduce with "collection" blocks the window until the read ends. The command dialog shows Running… (plugindialog.rs starts the command once the window has shown it running), and then the app runs it in the frame. Nothing else can be done meanwhile.

Plugin tools already run on a thread of their own (panes.rs start_plugin_run). Plugin commands don't, because they call host::run against the session.

A real case: BrasilData's "Imagem sem nuvens das cenas" reads 3 bands of Sentinel-2 L2A with a mask, stat: "first", over one municipality, about 40 scenes in 3 months. That froze the window for about 5 minutes.

pluginstart.rs says this outright: nothing is drawn until the command has finished, unless it is waiting in layer.addUrl or service.add, which leave the wait to the frame loop (#1319, #1513). The app already solves this for downloads. A plugin's layer.addUrl download is left to the app (call_requests). The call is undone quietly, the download runs off the frame, and the command runs again from the start once the download is in (#1202). The plugin sees {"pending": …} the first time and the layer the second time. Plugins written for the browser already handle pending.

Proposal

Choice in this proposal: treat cube.reduce on a collection called from a plugin command the same way as a download.

  1. The first call checks the parameters, as now. It then answers {"pending": true} and leaves the read to the app as a call request: the same parameters, owned by the plugin's call, keyed by those parameters.
  2. The app runs the reduce on a thread of its own. It has the progress and Cancel that cube.trend and raster.mosaic ([Feature]: Mosaic Rasters (raster.mosaic) on a thread of its own, with Cancel, started from the Workflows pane #2907) have in the Workflows pane, and it names the plugin.
  3. When the reduce lands, its layers are held, the way ran holds a trend. The command runs again from the start. That second cube.reduce call, with the same parameters, takes the held result at once and adds the layers.
  4. Cancel, or an error in the reduce, answers the command's rerun with that error. The plugin then says it as usual.

Choice: only "collection" reads go this way. layers, bands and local Zarr inputs are quick and stay in the frame. Several reduces in one call (one per band) are all left in the same call, so they run one after another on the thread, and the command runs again once all have landed. This is the same rule as several downloads in one call.

This covers cube.trend on a collection too: it has the same path and the same ran handoff.

Tests

  • A plugin command that calls cube.reduce with a collection gets pending and leaves no layer. After the run lands, the rerun adds the layer, and the project has one undo step.
  • Two reduces in one call: both are left, and there is one rerun.
  • Cancel: the rerun answers the cancel error. Nothing is added.
  • A call without "collection" runs in the frame as now.

Use

BrasilData's commands built on the INPE STAC: "cenas-sem-nuvens", and later the cube path's cube.reduce route. They already return {"pending": n} and say "lendo a área; a imagem vem quando chegar". With this change, that notice would also hold on the desktop.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions