the browser-facing portion of osu!
at master 810 B view raw
1<?php 2 3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 4// See the LICENCE file in the repository root for full licence text. 5 6namespace App\Libraries\Chat; 7 8use App\Events\ChatMessageEvent; 9use App\Models\Chat\Message; 10use DB; 11use Laravel\Octane\Facades\Octane; 12 13/** 14 * Wrapper to avoid SerializableClosure when dispatching ChatMessageEvent to task workers 15 */ 16class MessageTask 17{ 18 public function __construct(public Message $message) 19 { 20 } 21 22 public static function dispatch(Message $message) 23 { 24 // TODO: how to test Octane tasks? 25 DB::afterCommit(fn () => Octane::tasks()->dispatch([new static($message)])); 26 } 27 28 public function __invoke() 29 { 30 (new ChatMessageEvent($this->message))->broadcast(); 31 } 32}