Skip to content
This repository was archived by the owner on Oct 26, 2019. It is now read-only.

feat: Consume Docker system events asynchronously - #313

Merged
joelwurtz merged 7 commits into
docker-php:masterfrom
guillemcanal:feat/async-docker-system-events
Feb 17, 2019
Merged

feat: Consume Docker system events asynchronously#313
joelwurtz merged 7 commits into
docker-php:masterfrom
guillemcanal:feat/async-docker-system-events

Conversation

@guillemcanal

Copy link
Copy Markdown
Contributor

This feature make it possible to consume docker system events asynchronously using the DockerAsync client implementation.

Fixes issue #312

How to use

<?php

// filename : ./examples/listen-to-docker-events-async.php

use Docker\DockerAsync;
use Docker\Stream\ArtaxCallbackStream;

require dirname(__DIR__) . '/vendor/autoload.php';

Amp\Loop::run(function () {
    $docker = DockerAsync::create();

    /** @var ArtaxCallbackStream $events */
    $events = yield $docker->systemEvents();
    $events->onFrame(function ($event): void {
        // Do something with the docker event
        // var_dump($event);
    });

    // Start listening to Docker events
    $events->listen();

    // Close the request when a SIGINT signal is received
    Amp\Loop::onSignal(SIGINT, function (string $watcherId) use ($events) {
        $events->cancel();
        Amp\Loop::cancel($watcherId);
    });
});

@guillemcanal

Copy link
Copy Markdown
Contributor Author

@joelwurtz The job that generate the coverage report keep failing on me. And yet, #ItWorkOnMyMachine ;)

Do you have the same issue on your machine ? I'll try to use the same Docker binary than the job in question.

Guillem CANAL added 2 commits May 13, 2018 20:34
Reason: The travis step responsible to generate the coverage report is doing a
composer update --prefer-stable --prefer-lowest --no-interaction
which retreive an unstable version of amphp/artax.
please check https://github.com/amphp/artax/blob/master/CHANGELOG.md#306
@guillemcanal

guillemcanal commented May 13, 2018

Copy link
Copy Markdown
Contributor Author

@joelwurtz Okay, after much investigation I found why the Travis job that generate the coverage report was failing :

In the .travis.yml at https://github.com/docker-php/docker-php/blob/master/.travis.yml#L40 you are specifying the --prefer-lowest flag which make composer retrieve an unstable version of amphp/artax.

The issue in question was fixed in version 3.0.6. But for good measure, I just replaced $events->cancel() by Loop::stop() in my test case.

@joelwurtz

Copy link
Copy Markdown
Member

Thanks for this and sorry for the long awaited time.

@joelwurtz
joelwurtz merged commit cd8e309 into docker-php:master Feb 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants