denitsa-md/laravel-progress-status-broadcast

Broadcast progress status (percentage) of a long-running task.

0.1.0 2020-07-14 16:38 UTC

This package is auto-updated.

Last update: 2024-05-15 02:33:47 UTC


README

Latest Version on Packagist Build Status Packagist Downloads

I needed some simple functionality to broadcast progress events (10%, 20% ... 100% complete) when a long-running action was happening in the app.

This is also my first published package on packagist :)

Installation

You can install the package via composer:

composer require denitsa-md/laravel-progress-status-broadcast

Usage

This is how I've used the package in our project, except I used it in relation to a chunked collection.

Import the facade use DenitsaCm\ProgressStatusBroadcast\Facades\ProgressStatusBroadcast;

$products = Product::all();

ProgressStatusBroadcast::broadcastOn(new PrivateChannel('some-channel'))  // Specify the channel
    ->broadcastAs('products.process')  // Specify the event name
    ->total($products->count());       // Set the total amount so progress can be calcualted

$products->each(function ($product, $key) {
    $product->doSomething();
    ProgressStatusBroadcast::progress($key + 1); // Give the current item count to the progress status. Here I give it a +1 since the $key is 0-based and I want the progress to start from 1.
});

This will send a ProgressEvent via your configured broadcast driver.

Testing

Tests coming soon...

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email dmlechkova@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.