xproc / 3.0-steps

Repository for change requests to the standard step library and for official extension steps
10 stars 7 forks source link

p:sleep #574

Closed ndw closed 4 months ago

ndw commented 4 months ago

When interacting with external services, it's sometimes necessary to pause so the service has time to process your request.

This came up most recently in the test suite. We're using Sendria to test the p:send-mail step. The way it works is that Sendria provides an SMTP server and a web server. You send email to its SMTP port and it reports the results on its web server. Unfortunately, if you just make the calls in succession:

<p:send-mail ...>
<p:http-request method="get" ...>

it's fairly common for the summary to be in correct because Sendria is still ingesting the message.

I propose a p:sleep step:

  <p:declare-step type="p:sleep">
    <p:input port="source" sequence="true" content-types="any"/>
    <p:output port="result" sequence="true" content-types="any"/>
    <p:option name="duration" as="xs:duration" required="true"/>
  </p:declare-step>

The step is semantically the same as p:identity except that it will pause for a period not less than the specified duration before sending the document(s).

(We've sometimes argued that proposals for new steps belong in the V.next repository, but the absence of this step seems actively harmful and I propose we add it as an "erratum".)

gimsieke commented 4 months ago

Alternatively, add a wait attribute to p:identity and possibly to all steps? The semantic is that it waits the given amount of milliseconds (?) before executing the step.

ndw commented 4 months ago

Perhaps. I did consider suggesting it as an attribute on p:identity, but I think there's a risk if we go down that road that we'll find all sorts of one-off attributes to add and that's not going to be very discoverable for users.

Adding it to all the steps seems like overkill to me.

ndw commented 4 months ago

Having now implemented it and written a test, I think I'd prefer to say that the duration is a string that must be a valid xs:duration. It would be a lot nicer to write

<p:sleep duration="PT3S"/>

than it is to write

<p:sleep duration="{xs:dayTimeDuration('PT3S')}"/>
ndw commented 4 months ago

Make the sleep time a non-negative number of milliseconds.