Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Commands/CheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function handle(
while (true) {
$now = new CarbonImmutable();

if ($cache->get('laravel:pulse:restart') !== $lastRestart) {
if ($lastRestart !== $cache->get('laravel:pulse:restart')) {
return self::SUCCESS;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/WorkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function handle(
while (true) {
$now = new CarbonImmutable;

if ($cache->get('laravel:pulse:restart') !== $lastRestart) {
if ($lastRestart !== $cache->get('laravel:pulse:restart')) {
return self::SUCCESS;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/Ingest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface Ingest
/**
* Ingest the entries and updates.
*
* @param \Illuminate\Support\Collection<int, \Laravel\Pulse\Entries\Entry|\Laravel\Pulse\Entries\Update> $items
* @param \Illuminate\Support\Collection<int, \Laravel\Pulse\Entry|\Laravel\Pulse\Update> $items
*/
public function ingest(Collection $items): void;

Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface Storage
/**
* Store the entries and updates.
*
* @param \Illuminate\Support\Collection<int, \Laravel\Pulse\Entries\Entry|\Laravel\Pulse\Entries\Update> $items
* @param \Illuminate\Support\Collection<int, \Laravel\Pulse\Entry|\Laravel\Pulse\Update> $items
*/
public function store(Collection $items): void;

Expand Down
42 changes: 0 additions & 42 deletions src/Entries/SlowJobFinished.php

This file was deleted.

26 changes: 0 additions & 26 deletions src/Entries/Update.php

This file was deleted.

10 changes: 1 addition & 9 deletions src/Entries/Entry.php → src/Entry.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Laravel\Pulse\Entries;
namespace Laravel\Pulse;

class Entry
{
Expand All @@ -14,14 +14,6 @@ public function __construct(public string $table, public array $attributes)
//
}

/**
* The entries table.
*/
public function table(): string
{
return $this->table;
}

/**
* Resolve the entry for ingest and storage.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Facades/Pulse.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @method static \Laravel\Pulse\Pulse stopRecording()
* @method static \Laravel\Pulse\Pulse startRecording()
* @method static \Laravel\Pulse\Pulse filter(callable $filter)
* @method static \Laravel\Pulse\Pulse record(\Laravel\Pulse\Entries\Entry|\Laravel\Pulse\Entries\Update $entry)
* @method static \Laravel\Pulse\Pulse record(\Laravel\Pulse\Entry|\Laravel\Pulse\Update $entry)
* @method static \Laravel\Pulse\Pulse store(\Laravel\Pulse\Contracts\Ingest $ingest)
* @method static \Illuminate\Support\Collection entries()
* @method static \Laravel\Pulse\Pulse flushEntries()
Expand Down
6 changes: 3 additions & 3 deletions src/Ingests/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
use Illuminate\Support\Collection;
use Laravel\Pulse\Contracts\Ingest;
use Laravel\Pulse\Contracts\Storage;
use Laravel\Pulse\Entries\Entry;
use Laravel\Pulse\Entries\Update;
use Laravel\Pulse\Entry;
use Laravel\Pulse\Redis as RedisAdapter;
use Laravel\Pulse\Update;

class Redis implements Ingest
{
Expand All @@ -34,7 +34,7 @@ public function __construct(
/**
* Ingest the entries and updates.
*
* @param \Illuminate\Support\Collection<int, \Laravel\Pulse\Entries\Entry|\Laravel\Pulse\Entries\Update> $items
* @param \Illuminate\Support\Collection<int, \Laravel\Pulse\Entry|\Laravel\Pulse\Update> $items
*/
public function ingest(Collection $items): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Ingests/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(protected StorageContract $storage, protected Pulse
/**
* Ingest the entries and updates.
*
* @param \Illuminate\Support\Collection<int, \Laravel\Pulse\Entries\Entry|\Laravel\Pulse\Entries\Update> $items
* @param \Illuminate\Support\Collection<int, \Laravel\Pulse\Entry|\Laravel\Pulse\Update> $items
*/
public function ingest(Collection $items): void
{
Expand Down
10 changes: 4 additions & 6 deletions src/Pulse.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
use Illuminate\Support\Collection;
use Illuminate\Support\Lottery;
use Laravel\Pulse\Contracts\Ingest;
use Laravel\Pulse\Entries\Entry;
use Laravel\Pulse\Entries\Update;
use Laravel\Pulse\Recorders\Concerns\ConfiguresAfterResolving;
use RuntimeException;
use Throwable;
Expand All @@ -31,7 +29,7 @@ class Pulse
/**
* The list of queued entries or updates.
*
* @var \Illuminate\Support\Collection<int, \Laravel\Pulse\Entries\Entry|\Laravel\Pulse\Entries\Update>
* @var \Illuminate\Support\Collection<int, \Laravel\Pulse\Entry|\Laravel\Pulse\Update>
*/
protected Collection $entries;

Expand All @@ -43,7 +41,7 @@ class Pulse
/**
* The entry filters.
*
* @var \Illuminate\Support\Collection<int, (callable(\Laravel\Pulse\Entries\Entry|\Laravel\Pulse\Entries\Update): bool)>
* @var \Illuminate\Support\Collection<int, (callable(\Laravel\Pulse\Entry|\Laravel\Pulse\Update): bool)>
*/
protected Collection $filters;

Expand Down Expand Up @@ -179,7 +177,7 @@ public function startRecording(): self
/**
* Filter incoming entries using the provided filter.
*
* @param (callable(\Laravel\Pulse\Entries\Entry|\Laravel\Pulse\Entries\Update): bool) $filter
* @param (callable(\Laravel\Pulse\Entry|\Laravel\Pulse\Update): bool) $filter
*/
public function filter(callable $filter): self
{
Expand Down Expand Up @@ -227,7 +225,7 @@ public function store(Ingest $ingest): self
/**
* The pending entries to be recorded.
*
* @return \Illuminate\Support\Collection<int, \Laravel\Pulse\Entries\Entry|\Laravel\Pulse\Entries\Update>
* @return \Illuminate\Support\Collection<int, \Laravel\Pulse\Entry|\Laravel\Pulse\Update>
*/
public function entries()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Recorders/CacheInteractions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Cache\Events\CacheHit;
use Illuminate\Cache\Events\CacheMissed;
use Illuminate\Support\Str;
use Laravel\Pulse\Entries\Entry;
use Laravel\Pulse\Entry;
use Laravel\Pulse\Pulse;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Recorders/Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Foundation\Application;
use Illuminate\Support\Str;
use Laravel\Pulse\Entries\Entry;
use Laravel\Pulse\Entry;
use Laravel\Pulse\Pulse;
use Throwable;

Expand Down
15 changes: 9 additions & 6 deletions src/Recorders/Jobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
use Illuminate\Queue\Events\JobProcessing;
use Illuminate\Queue\Events\JobQueued;
use Illuminate\Queue\Events\JobReleasedAfterException;
use Laravel\Pulse\Entries\Entry;
use Laravel\Pulse\Entries\SlowJobFinished;
use Laravel\Pulse\Entries\Update;
use Laravel\Pulse\Entry;
use Laravel\Pulse\Pulse;
use Laravel\Pulse\Update;

/**
* @internal
Expand Down Expand Up @@ -86,9 +85,13 @@ public function record(JobReleasedAfterException|JobFailed|JobProcessed|JobProce
return null;
}

return tap(new SlowJobFinished(
(string) $event->job->uuid(),
$duration,
return tap(new Update(
$this->table,
['job_uuid' => (string) $event->job->uuid()],
fn (array $attributes) => [
'slowest' => max($attributes['slowest'] ?? 0, $duration),
'slow' => $attributes['slow'] + 1,
],
), fn () => $this->lastJobStartedProcessingAt = null);
}
}
2 changes: 1 addition & 1 deletion src/Recorders/OutgoingRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Illuminate\Foundation\Application;
use Illuminate\Http\Client\Factory as HttpFactory;
use Illuminate\Support\Str;
use Laravel\Pulse\Entries\Entry;
use Laravel\Pulse\Entry;
use Laravel\Pulse\Pulse;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
Expand Down
4 changes: 2 additions & 2 deletions src/Recorders/QueueSizes.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Illuminate\Queue\QueueManager;
use Illuminate\Support\Collection;
use Illuminate\Support\Enumerable;
use Laravel\Pulse\Entries\Entry;
use Laravel\Pulse\Entry;
use Laravel\Pulse\Events\Beat;

/**
Expand Down Expand Up @@ -44,7 +44,7 @@ public function __construct(
/**
* Record the queue sizes.
*
* @return \Illuminate\Support\Enumerable<int, \Laravel\Pulse\Entries\Entry>
* @return \Illuminate\Support\Enumerable<int, \Laravel\Pulse\Entry>
*/
public function record(Beat $event): Enumerable
{
Expand Down
2 changes: 1 addition & 1 deletion src/Recorders/Requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
use Laravel\Pulse\Entries\Entry;
use Laravel\Pulse\Entry;
use Laravel\Pulse\Pulse;
use Symfony\Component\HttpFoundation\Response;

Expand Down
2 changes: 1 addition & 1 deletion src/Recorders/SlowQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Carbon\CarbonImmutable;
use Illuminate\Config\Repository;
use Illuminate\Database\Events\QueryExecuted;
use Laravel\Pulse\Entries\Entry;
use Laravel\Pulse\Entry;
use Laravel\Pulse\Pulse;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Recorders/SystemStats.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Laravel\Pulse\Recorders;

use Illuminate\Config\Repository;
use Laravel\Pulse\Entries\Entry;
use Laravel\Pulse\Entry;
use Laravel\Pulse\Events\Beat;
use RuntimeException;

Expand Down
29 changes: 25 additions & 4 deletions src/Storage/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use Illuminate\Database\DatabaseManager;
use Illuminate\Support\Collection;
use Laravel\Pulse\Contracts\Storage;
use Laravel\Pulse\Entries\Entry;
use Laravel\Pulse\Entries\Update;
use Laravel\Pulse\Entry;
use Laravel\Pulse\Update;

class Database implements Storage
{
Expand All @@ -27,7 +27,7 @@ public function __construct(
/**
* Store the entries and updates.
*
* @param \Illuminate\Support\Collection<int, \Laravel\Pulse\Entries\Entry|\Laravel\Pulse\Entries\Update> $items
* @param \Illuminate\Support\Collection<int, \Laravel\Pulse\Entry|\Laravel\Pulse\Update> $items
*/
public function store(Collection $items): void
{
Expand All @@ -43,7 +43,28 @@ public function store(Collection $items): void
->map(fn (Collection $inserts) => $inserts->pluck('attributes')->all())
->each($this->connection()->table($table)->insert(...)));

$updates->each(fn (Update $update) => $update->perform($this->connection()));
$updates->each(function (Update $update) {
if (is_array($update->attributes)) {
$this->connection()
->table($update->table)
->where($update->conditions)
->update($update->attributes);
} else {
$existing = $this->connection()
->table($update->table)
->where($update->conditions)
->first();

if ($existing === null) {
return;
}

$this->connection()
->table($update->table)
->where($update->conditions)
->update(($update->attributes)((array) $existing));
}
});
});
}

Expand Down
28 changes: 28 additions & 0 deletions src/Update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Laravel\Pulse;

use Closure;

class Update
{
/**
* @param array<string, mixed> $conditions
* @param array<string, mixed>|(\Closure(array<string, mixed>): array<string, mixed>) $attributes
*/
public function __construct(
public string $table,
public array $conditions,
public array|Closure $attributes
) {
//
}

/**
* Resolve the update for ingest and storage.
*/
public function resolve(): self
{
return $this;
}
}
Loading