PHP code example of seiger / stask

1. Go to this page and download the library: Download seiger/stask library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

seiger / stask example snippets


use Seiger\sTask\Facades\sTask;

// Create a new task
$task = sTask::create(
    identifier: 'product_sync',
    action: 'import',
    data: ['file' => '/path/to/products.csv'],
    priority: 'high',
    userId: evo()->getLoginUserID()
);

// Process pending tasks
$processedCount = sTask::processPendingTasks();

// Get task statistics
$stats = sTask::getStats();

// Get all incomplete tasks (pending, preparing, running)
$incomplete = \Seiger\sTask\Models\sTaskModel::incomplete()->get();

 namespace YourNamespace\Workers;

use Seiger\sTask\Workers\BaseWorker;
use Seiger\sTask\Models\sTaskModel;

class EmailWorker extends BaseWorker
{
    public function identifier(): string
    {
        return 'email_campaign';
    }
    
    public function scope(): string
    {
        return 'notifications';
    }
    
    public function icon(): string
    {
        return '<i class="fa fa-envelope"></i>';
    }
    
    public function title(): string
    {
        return 'Email Campaign';
    }
    
    public function description(): string
    {
        return 'Send bulk email campaigns to users';
    }
    
    public function taskSend(sTaskModel $task, array $options = []): void
    {
        $this->pushProgress(10, 'Preparing email data');
        
        $recipients = $options['recipients'] ?? [];
        $subject = $options['subject'] ?? 'Campaign';
        
        foreach ($recipients as $email) {
            // Send email logic
            $this->pushProgress(50 + (40 / count($recipients)), "Sent to {$email}");
        }
        
        $this->markFinished('All emails sent successfully');
    }
    
    public function settings(): array
    {
        return [
            'smtp_host' => 'localhost',
            'smtp_port' => 587,
            'from_email' => '[email protected]',
        ];
    }
}

if (evo()->getConfig('check_sTask', false)) {
    // sTask is available
    $task = \Seiger\sTask\Facades\sTask::create(
        identifier: 'my_worker',
        action: 'process',
        data: []
    );
}

use Seiger\sTask\Models\sTaskModel;

// Get tasks by status
$pending = sTaskModel::pending()->get();
$running = sTaskModel::running()->get();
$completed = sTaskModel::finished()->get();
$failed = sTaskModel::failed()->get();

// Get all incomplete tasks (pending, preparing, running)
$incomplete = sTaskModel::incomplete()->get();

// Get tasks by priority
$highPriority = sTaskModel::highPriority()->get();
$normalPriority = sTaskModel::normalPriority()->get();
$lowPriority = sTaskModel::lowPriority()->get();
bash
php artisan package:install
bash
php artisan vendor:publish --tag=stask
bash
php artisan migrate