PHP code example of codetechnl / laravel-taskbridge
1. Go to this page and download the library: Download codetechnl/laravel-taskbridge 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/ */
codetechnl / laravel-taskbridge example snippets
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class SendDailyReport implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function handle(): void
{
// your logic here
}
}
use CodeTechNL\TaskBridge\Contracts\HasPredefinedCronExpression;
class SendDailyReport implements HasPredefinedCronExpression, ShouldQueue
{
public function cronExpression(): string
{
return '0 8 * * *'; // every day at 08:00
}
public function handle(): void { ... }
}
use CodeTechNL\TaskBridge\Contracts\HasPredefinedCronExpression;
class GenerateReport implements HasPredefinedCronExpression, ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct(
public readonly string $type,
public readonly int $rows = 1000,
public readonly bool $dryRun = false,
) {}
public function cronExpression(): string { return '0 6 * * 1'; }
public function handle(): void { /* uses $this->type, $this->rows, $this->dryRun */ }
}
public function __construct(
public readonly ?string $recipient, //
public function __construct(
public readonly ?int $retentionDays = null, // optional — leave blank to use config default
) {}
public function handle(): void
{
$days = $this->retentionDays ?? (int) config('taskbridge.logging.retention_days', 30);
// ...
}
use CodeTechNL\TaskBridge\Contracts\HasCustomLabel;
class SendDailyReport implements HasCustomLabel, ShouldQueue
{
public function taskLabel(): string
{
return 'Daily Report — Finance';
}
}
use CodeTechNL\TaskBridge\Contracts\HasGroup;
class SendDailyReport implements HasGroup, ShouldQueue
{
public function group(): string
{
return 'Reporting'; // Overrides the folder-based detection.
}
}
use CodeTechNL\TaskBridge\Concerns\SkipOnMaintenance;
class SendDailyReport implements ShouldQueue
{
use SkipOnMaintenance;
public function handle(): void { ... }
}
use CodeTechNL\TaskBridge\Concerns\SkipOnMaintenance;
use CodeTechNL\TaskBridge\Contracts\RunsConditionally;
class SendDailyReport implements RunsConditionally, ShouldQueue
{
use SkipOnMaintenance;
public function shouldRun(): bool
{
return $this->someCondition(); // only checked when not in maintenance
}
}
use CodeTechNL\TaskBridge\Contracts\RunsConditionally;
class SendDailyReport implements RunsConditionally, ShouldQueue
{
public function shouldRun(): bool
{
return $this->someCondition();
}
}
use CodeTechNL\TaskBridge\Concerns\HasJobOutput;
use CodeTechNL\TaskBridge\Contracts\ReportsTaskOutput;
class ImportProducts implements ReportsTaskOutput, ShouldQueue
{
use HasJobOutput;
public function handle(): void
{
$processed = 0;
$skipped = 0;
// ... your import logic ...
$this->reportOutput([
'processed' => $processed,
'skipped' => $skipped,
]);
}
}