Skip to content

Commit

Permalink
Implements SMF\Tasks\GenericTask
Browse files Browse the repository at this point in the history
A class for running background tasks with custom callable functions. Similar to SMF\Tasks\GenericScheduledTask, except that this is for tasks that are not scheduled.

Signed-off-by: Jon Stovell <[email protected]>
  • Loading branch information
Sesquipedalian committed Mar 30, 2024
1 parent 6e3da27 commit 0128b9b
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Sources/Tasks/GenericTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/**
* Simple Machines Forum (SMF)
*
* @package SMF
* @author Simple Machines https://www.simplemachines.org
* @copyright 2024 Simple Machines and individual contributors
* @license https://www.simplemachines.org/about/smf/license.php BSD
*
* @version 3.0 Alpha 1
*/

declare(strict_types=1);

namespace SMF\Tasks;

use SMF\Utils;

/**
* A class for running background tasks with custom callable functions.
*/
class GenericTask extends BackgroundTask
{
/**
* This executes the task.
*
* @return bool Always returns true.
* @todo PHP 8.2: This can be changed to return type: true.
*/
public function execute(): bool
{
$callable_task = Utils::getCallable($this->_details['callable']);

// Perform the task.
if (!empty($callable_task)) {
call_user_func($callable_task);
}

return true;
}
}

?>

0 comments on commit 0128b9b

Please sign in to comment.