Skip to content

Commit

Permalink
Write all of the output from each process to the screen (#12)
Browse files Browse the repository at this point in the history
* add output to screen options

* fix lint, dont assume 0.00s

* make $onStart protected in pool

* split out tags into trait, update some code formatting

* better null check
  • Loading branch information
Harry Bragg authored Oct 9, 2017
1 parent 23d19d9 commit 851cbcd
Show file tree
Hide file tree
Showing 19 changed files with 3,063 additions and 157 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor/
composer.lock
/tests/report/
.idea
.DS_Store
52 changes: 28 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,30 @@ SHELL = /bin/sh

DOCKER ?= $(shell which docker)
VOLUME := /srv
DOCKER_RUN_BASE := ${DOCKER} run --rm -t -v $$(pwd):${VOLUME} -w ${VOLUME}
DOCKER_RUN := docker-compose run --rm test
IMAGE ?= graze/php-alpine:test
DOCKER_RUN := ${DOCKER} run --rm -t -v $$(pwd):${VOLUME} -w ${VOLUME} ${IMAGE}

PREFER_LOWEST ?=

.PHONY: install composer clean help run
.PHONY: build build-update composer-% clean help run
.PHONY: lint lint-fix
.PHONY: test test-unit test-example test-lowest test-matrix test-coverage test-coverage-html test-coverage-clover
.PHONY: test test-unit test-lowest test-matrix test-coverage test-coverage-html test-coverage-clover

.SILENT: help

# Building

build: ## Download the dependencies then build the image :rocket:.
make 'composer-install --optimize-autoloader --ignore-platform-reqs'
make 'composer-install --prefer-dist --optimize-autoloader'

build-update: ## Update all dependencies
make 'composer-update --optimize-autoloader ${PREFER_LOWEST}'
make 'composer-update --prefer-dist --optimize-autoloader ${PREFER_LOWEST}'

composer-%: ## Run a composer command, `make "composer-<command> [...]"`.
${DOCKER} run -t --rm \
-v $$(pwd):/usr/src/app \
-v ~/.composer:/root/composer \
-v ~/.ssh:/root/.ssh:ro \
graze/composer --ansi --no-interaction $* $(filter-out $@,$(MAKECMDGOALS))
-v $$(pwd):/app \
-v ~/.composer:/tmp \
composer --ansi --no-interaction $* $(filter-out $@,$(MAKECMDGOALS))

# Testing

Expand All @@ -42,24 +41,29 @@ lint-fix: ## Run phpcsf and fix possible lint errors.
test-unit: ## Run the unit testsuite.
${DOCKER_RUN} vendor/bin/phpunit --testsuite unit

test-example: ## Run the example application
${DOCKER_RUN} php tests/example/app.php
test-examples: ## Test the pre-build examples
test-examples: test-example-table test-example-lines

test-example-table: ## Run the example application
${DOCKER_RUN} php tests/example/table.php

test-example-lines: ## Run the example application
${DOCKER_RUN} php tests/example/lines.php

test-lowest: ## Test using the lowest possible versions of the dependencies
test-lowest: PREFER_LOWEST=--prefer-lowest
test-lowest: PREFER_LOWEST=--prefer-lowest --prefer-stable
test-lowest: build-update test

test-matrix: ## Run the unit tests against multiple targets.
${MAKE} DOCKER_RUN="${DOCKER_RUN_BASE} php:5.5-alpine" PREFER_LOWEST=--prefer-lowest build-update test
${MAKE} DOCKER_RUN="${DOCKER_RUN_BASE} php:5.6-alpine" PREFER_LOWEST=--prefer-lowest build-update test
${MAKE} DOCKER_RUN="${DOCKER_RUN_BASE} php:7.0-alpine" PREFER_LOWEST=--prefer-lowest build-update test
${MAKE} DOCKER_RUN="${DOCKER_RUN_BASE} php:7.1-alpine" PREFER_LOWEST=--prefer-lowest build-update test
${MAKE} DOCKER_RUN="${DOCKER_RUN_BASE} hhvm/hhvm:latest" PREFER_LOWEST=--prefer-lowest build-update test
${MAKE} DOCKER_RUN="${DOCKER_RUN_BASE} php:5.5-alpine" build-update test
${MAKE} DOCKER_RUN="${DOCKER_RUN_BASE} php:5.6-alpine" build-update test
${MAKE} DOCKER_RUN="${DOCKER_RUN_BASE} php:7.0-alpine" build-update test
${MAKE} DOCKER_RUN="${DOCKER_RUN_BASE} php:7.1-alpine" build-update test
${MAKE} DOCKER_RUN="${DOCKER_RUN_BASE} hhvm/hhvm:latest" build-update test
${MAKE} IMAGE="php:5.6-alpine" test
${MAKE} IMAGE="php:7.0-alpine" test
${MAKE} IMAGE="php:7.1-alpine" test
${MAKE} IMAGE="hhvm/hhvm:latest" test

test-matrix-lowest: ## Run the unit tests against
${MAKE} build-update PREFER_LOWEST='--prefer-lowest --prefer-stable'
${MAKE} test-matrix
${MAKE} build-update

test-coverage: ## Run all tests and output coverage to the console.
${DOCKER_RUN} phpdbg7 -qrr vendor/bin/phpunit --coverage-text
Expand All @@ -76,4 +80,4 @@ help: ## Show this help message.
echo "usage: make [target] ..."
echo ""
echo "targets:"
fgrep --no-filename "##" $(MAKEFILE_LIST) | fgrep --invert-match $$'\t' | sed -e 's/: ## / - /'
egrep '^(.+)\:\ ##\ (.+)' ${MAKEFILE_LIST} | column -t -c 2 -s ':#'
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ $pool->run(); // blocking that will run till it finishes

Visual output of the parallel processes

Requires: `graze/console-diff-renderer`

```php
$table = new Table($output);
for ($i = 0; $i < 5; $i++) {
Expand All @@ -53,6 +51,23 @@ $table->run();

[![asciicast](https://asciinema.org/a/55r0rf9zin49s751j3a8zbdw1.png)](https://asciinema.org/a/55r0rf9zin49s751j3a8zbdw1)

### Lines

Write the output of each process to the screen

```php
$pool = new \Graze\ParallelProcess\Pool();
$pool->setMaxSimultaneous(3);
$lines = new Lines($output, $pool);
for ($i = 0; $i < 5; $i++) {
$time = $i + 5;
$lines->add(new Process(sprintf('for i in `seq 1 %d` ; do date ; sleep 1 ; done', $time)), ['sleep' . $time]);
}
$lines->run();
```

[![asciicast](https://asciinema.org/a/Zpr1JhGTxmsoDXBFRjsRek4wt.png)](https://asciinema.org/a/Zpr1JhGTxmsoDXBFRjsRek4wt)

## Testing

``` bash
Expand Down
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,18 @@
"require": {
"php": "^5.5 | ^7.0",
"symfony/process": "^2.8 | ^3.2",
"graze/data-structure": "^2.0"
"graze/data-structure": "^2.0",
"graze/console-diff-renderer": "^0.6.1"
},
"require-dev": {
"phpunit/phpunit": "^4.2 | ^5.2",
"squizlabs/php_codesniffer": "^2.9",
"graze/standards": "^1.0",
"symfony/console": "^3.1",
"graze/console-diff-renderer": "^0.6.1",
"mockery/mockery": "^0.9.9"
},
"suggest": {
"symfony/console": "To use the Table to print current runs",
"graze/console-diff-renderer": "To use the Table efficiently"
"symfony/console": "To use the Table to print current runs"
},
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit 851cbcd

Please sign in to comment.