1. Go to this page and download the library: Download codysseydev/argus 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/ */
codysseydev / argus example snippets
// config/argus.php
'schedule' => [
'enabled' => true, // set false to register the schedule yourself
'partitions_at' => '00:10',
],
use Argus\Query\FilterBuilder;
use Argus\Query\JobQueryService;
use Argus\Support\TransitionType;
use Carbon\CarbonImmutable;
public function __construct(private JobQueryService $argus) {}
// 1. Search current job state. Returns list<JobSummary> (empty if nothing matches).
$jobs = $this->argus->search(
FilterBuilder::make()
->tenant('tenant-1')
->status(TransitionType::FAILED)
->queue('emails')
->attemptBetween(2, 5)
->between(CarbonImmutable::parse('-7 days'), CarbonImmutable::now())
->correlation('request_id', 'r-abc123')
->limit(50)
->offset(0)
->build()
);
foreach ($jobs as $job) {
$job->jobUuid;
$job->status; // 'queued' | 'processing' | 'processed' | 'failed' | 'released'
$job->isInFlight(); // true when the job has no terminal transition yet
}
// 2. Replay one job's full lifecycle, ascending by sequence. list<TransitionRecord>.
$history = $this->argus->getHistory($jobUuid);
// 3. Group failures by exception fingerprint within a window. list<FailureGroup>.
$groups = $this->argus->groupFailures(
FilterBuilder::make()
->between(CarbonImmutable::parse('-24 hours'), CarbonImmutable::now())
->build()
);
foreach ($groups as $group) {
$group->fingerprint; // stable root-cause key
$group->representativeMessage; // a scrubbed example message
$group->count; // failures collapsed into this group
$group->firstSeen;
$group->lastSeen;
}
// config/argus.php
'retention_days' => 30,
use Argus\Query\FilterBuilder;
use Argus\SavedSearches\SavedSearchService;
use Argus\Support\TransitionType;
public function __construct(private SavedSearchService $searches) {}
// Define a saved search: a name + the same filter object you pass to search().
$saved = $this->searches->create(
'failed-emails',
FilterBuilder::make()
->queue('emails')
->status(TransitionType::FAILED)
->build(),
);
$all = $this->searches->all(); // list<SavedSearch>
$one = $this->searches->find($saved->id);
$this->searches->update($saved->id, 'failed-emails', $newFilter);
$this->searches->delete($saved->id);
// Re-run it. Returns the same list<JobSummary> as running the inline filter.
$jobs = $this->searches->results($saved->id);
use Argus\Alerting\AlertService;
public function __construct(private AlertService $alerts) {}
$rule = $this->alerts->attach(
savedSearchId: $saved->id,
name: 'too-many-failed-emails',
threshold: 50, // fire when MORE THAN 50 jobs match
windowSeconds: 900, // over a rolling 15-minute window (overrides the saved filter's since/until)
cooldownSeconds: 1800, // damp flapping: suppress re-alerts within 30 minutes
sinks: ['slack'], // which sink(s) to notify (keys from config('argus.alerting.sinks'))
enabled: true,
);
$this->alerts->all();
$this->alerts->forSavedSearch($saved->id);
$this->alerts->update($rule->id, 'too-many-failed-emails', 100, 900, 1800, ['slack', 'webhook'], true);
$this->alerts->delete($rule->id);
// config/argus.php
'alerting' => [
'enabled' => true, // set false to register the schedule yourself
'cadence' => '*/5 * * * *', // cron expression for how often alerts evaluate
'sinks' => [
'slack' => ['webhook_url' => env('ARGUS_SLACK_WEBHOOK_URL')],
'webhook' => ['url' => env('ARGUS_ALERT_WEBHOOK_URL'), 'headers' => []],
],
],
use Argus\Alerting\AlertNotification;
use Argus\Contracts\AlertSink;
final readonly class PagerDutySink implements AlertSink
{
public function name(): string
{
return 'pagerduty'; // the key a rule references in its sinks list
}
public function send(AlertNotification $notification): void
{
// POST $notification to PagerDuty. Throw on failure so the queued job retries.
}
}
use Argus\Alerting\AlertSinkRegistry;
public function boot(AlertSinkRegistry $sinks): void
{
$sinks->register(new PagerDutySink(/* ... */));
}