Skip to content

Commit

Permalink
reproduction of laravel/framework#49890
Browse files Browse the repository at this point in the history
  • Loading branch information
naquad committed Feb 23, 2024
1 parent 3d6d006 commit 2c7725f
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 4 deletions.
8 changes: 4 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_KEY=base64:EcXczznJFhqpOEm3Pk5h8s9Q5lVJpXdjc2IJ9UbUe5s=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=bug_report
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
CACHE_DRIVER=redis
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
QUEUE_CONNECTION=redis
SESSION_DRIVER=file
SESSION_LIFETIME=120

Expand Down
49 changes: 49 additions & 0 deletions app/Console/Commands/PocCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace App\Console\Commands;

use App\Jobs\ProcessRecord;
use App\Models\Record;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Redis;

class PocCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:poc';

/**
* The console command description.
*
* @var string
*/
protected $description = 'ShouldBeUnique issue reproduction command.';

/**
* Execute the console command.
*/
public function handle()
{
Redis::flushdb();
Record::truncate();

$r = Record::create(['name' => 'test']);

ProcessRecord::dispatch($r);
$r->delete();
Artisan::call('queue:work', ['--once' => true]);

$keys = Redis::keys('*');
if (!$keys) {
$this->info('No keys found in Redis, lock removed');
} else {
$this->error('Keys found in Redis, lock not removed');
dump($keys);
}
}
}
34 changes: 34 additions & 0 deletions app/Jobs/ProcessRecord.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Jobs;

use App\Models\Record;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class ProcessRecord implements ShouldQueue, ShouldBeUnique
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* Create a new job instance.
*/
public function __construct(
public Record $record
)
{
//
}

/**
* Execute the job.
*/
public function handle(): void
{
//
}
}
15 changes: 15 additions & 0 deletions app/Models/Record.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Record extends Model
{
use HasFactory;

public $fillable = [
'name',
];
}
28 changes: 28 additions & 0 deletions database/migrations/2024_02_23_160112_create_records_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('records', function (Blueprint $table) {
$table->id();
$table->string('name')->unique();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('records');
}
};

0 comments on commit 2c7725f

Please sign in to comment.