npm-run-all icon indicating copy to clipboard operation
npm-run-all copied to clipboard

Feature request - Delay option.

Open alexdevero opened this issue 6 years ago • 8 comments

Feature request for a flag to specify delay when two or more tasks should run in parallel. For case when two or more tasks has to be running simultaneously, but there has to be a delay before starting task number two.

Example: run postcss:dev script, wait for a 1000 ms and run start script. Then, keep both running in parallel.

"postcss:dev": "postcss --config postcss.config.js -o css/styles.css css/**/*.postcss --map --watch",
"start": "react-scripts-ts start",
"start:dev": "sh -ac '. ./.env.development;' && npm-run-all -p postcss:dev --delay=1000 start"

Without the delay, app will reload before the postcss gets compiled which leads to styles not loaded properly.

alexdevero avatar Sep 14 '18 12:09 alexdevero

Is there some progress on this feature?

estoel81 avatar Feb 27 '19 14:02 estoel81

If you need a delay, you should use delay-cli

To the original example, here is my preferred solution:

  • have a prep-build script that does your initial CSS build
  • have a separate watch script that watches for changes and rebuilds your CSS based on that
  • have your dev script run the prep-build script, and then run all your watch scripts and your development server in parallel

Example at https://github.com/TehShrike/memorize-text-app/blob/3c5126f70b8485541f6d6e69dda6ec496fafa1b4/package.json#L12

TehShrike avatar Feb 27 '19 15:02 TehShrike

Thank you, but i'm using it differently.

"pretest:integration": "webdriver-manager update",
"test:integration": "run-p test:integration:*",
"test:integration:student": "run-s test:integration:student:*",
"test:integration:student:desktop": "ng e2e student-integration --webdriver-update false",
"test:integration:student:tablet": "ng e2e student-integration --webdriver-update false --protractorConfig test/integration/protractor-tablet.conf.js",
"test:integration:student:mobile": "ng e2e student-integration --webdriver-update false --protractorConfig test/integration/protractor-mobile.conf.js",
"test:integration:teacher": "ng e2e teacher-integration --webdriver-update false",
"test:integration:preview": "ng e2e preview-integration --webdriver-update false",

It would be nice to set an interval between parallel jobs. Do you think thats possible?

estoel81 avatar Mar 04 '19 07:03 estoel81

If you're setting a delay between them, then they're not running in parallel :-x

TehShrike avatar Mar 04 '19 15:03 TehShrike

Well, that's just not true. For example, start a server listening on a port and wait a few beats for the server to start. Then, start a client which connects to that server over the port and has a conversation. If the client starts before the server (possible due to variations in process startup), then the client will crash with no server endpoint. Solving this problem by waiting for a file or sleeping until the port is up and being used is the current best method (I use lsof -ti tcp:<port> for this purpose). A delay would be nicer. Or, for my purposes a way to specify if a port is active, but that's not the original request (for a delay).

These two processes are definitely running in parallel, they just need a staggered start.

codeedog avatar Apr 17 '19 22:04 codeedog

I would recommend making a CLI script that polls for a port to be open, that exits with a code 0 once the port is open, or exits with a non-0 exit code after some timeout period. Then you can run your client like poll-for-port --port=8080 --timeout=5000 && node ./my-client-test-thingy.js

This functionality seems out of scope for npm-run-all

TehShrike avatar Apr 18 '19 13:04 TehShrike

I have often recommended wait-on package.

mysticatea avatar Apr 18 '19 14:04 mysticatea

This shouldn't be part of npm-run-all. There's already the native sleep on most OSs and you can use delay-cli if you want a cross-platform version. Or even the excellent wait-on, which sounds perfect for your scope instead of waiting an arbitrary time.

fregante avatar Jun 07 '19 14:06 fregante