{"id":1283,"date":"2025-04-20T23:08:59","date_gmt":"2025-04-20T14:08:59","guid":{"rendered":"https:\/\/shinke1987.net\/?p=1283"},"modified":"2025-04-20T23:08:59","modified_gmt":"2025-04-20T14:08:59","slug":"laravel%e3%81%a7%e3%81%ae%e3%82%ad%e3%83%a5%e3%83%bc%e3%81%ae%e5%8b%95%e4%bd%9c%e7%a2%ba%e8%aa%8d","status":"publish","type":"post","link":"https:\/\/shinke1987.net\/?p=1283","title":{"rendered":"Laravel\u3067\u306e\u30ad\u30e5\u30fc\u306e\u52d5\u4f5c\u78ba\u8a8d"},"content":{"rendered":"\n<h2 id=\"toc0\" class=\"wp-block-heading\">\u524d\u63d0<\/h2>\n\n\n\n<p>Laravel\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\uff1a11.20.0<\/p>\n\n\n\n<p>\u30ad\u30e5\u30fc\u306e\u5185\u5bb9\u306fDB\u306b\u4fdd\u5b58\u3059\u308b\u8a2d\u5b9a\u3067\u3001\u5fc5\u8981\u306a\u30c6\u30fc\u30d6\u30eb\u3082\u30de\u30a4\u30b0\u30ec\u30fc\u30c8\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u3092\u524d\u63d0\u3068\u3059\u308b\u3002<\/p>\n\n\n\n<p>\uff08\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u72b6\u614b\u3067\u30de\u30a4\u30b0\u30ec\u30fc\u30c8\u3059\u308c\u3070\u305d\u3046\u306a\u3063\u3066\u3044\u308b\u306f\u305a\uff09<\/p>\n\n\n\n<p>\u5168\u4f53\u7684\u306a\u6ce8\u610f\u70b9\u3068\u3057\u3066\u30b8\u30e7\u30d6\u3084\u4ed6\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u5909\u66f4\u3057\u305f\u5f8c\u3001<br>\u30ad\u30e5\u30fc\u30ef\u30fc\u30ab\u3092\u518d\u8d77\u52d5\u3059\u308b\u3053\u3068\u3092\u5fd8\u308c\u305a\u306b\u3002<\/p>\n\n\n\n<h2 id=\"toc1\" class=\"wp-block-heading\">\u6e96\u5099<\/h2>\n\n\n\n<h3 id=\"toc2\" class=\"wp-block-heading\">\u30b8\u30e7\u30d6\u306e\u4f5c\u6210<\/h3>\n\n\n\n<p>\u6b21\u306e\u30b3\u30de\u30f3\u30c9\u3067\u30ad\u30e5\u30fc\u306b\u5165\u308c\u308b\u30b8\u30e7\u30d6\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nphp artisan make:job TestJob\n<\/pre><\/div>\n\n\n<p>\u4f5c\u6210\u3055\u308c\u305fTestJob\u30af\u30e9\u30b9\u306ehandle\u30e1\u30bd\u30c3\u30c9\u3092\u6b21\u306e\u3088\u3046\u306b\u7de8\u96c6\u3059\u308b\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\npublic function handle(): void\n\n{\n\n    Log::info(&#039;TestJob&#039;);\n\n}\n<\/pre><\/div>\n\n\n<h3 id=\"toc3\" class=\"wp-block-heading\">\u52d5\u4f5c\u78ba\u8a8d\u7528\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u306e\u4f5c\u6210<\/h3>\n\n\n\n<p>\u6b21\u306e\u30b3\u30de\u30f3\u30c9\u3067\u4eca\u56de\u306e\u52d5\u4f5c\u78ba\u8a8d\u7528\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nphp artisan make:controller Test\n<\/pre><\/div>\n\n\n<p>\u4f5c\u6210\u3055\u308c\u305fTest\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u306b\u6b21\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u8a18\u3059\u308b\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\npublic function TestJob()\n\n{\n\n    TestJob::dispatch();\n\n    return view(&#039;welcome&#039;);\n\n}\n<\/pre><\/div>\n\n\n<h3 id=\"toc4\" class=\"wp-block-heading\">\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u306e\u8a2d\u5b9a<\/h3>\n\n\n\n<p>routes\/web.php\u306b\u3066\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u30eb\u30fc\u30c8\u3092\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\u3057\u3001\uff08\u524a\u9664\u3057\u3066\u3082\u826f\u3044\uff09<br>\u6b21\u306e\u3088\u3046\u306b\u7de8\u96c6\u3059\u308b\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n\/\/Route::get(&#039;\/&#039;, function () {\n\n\/\/    return view(&#039;welcome&#039;);\n\n\/\/});\n\nRoute::get(&#039;\/&#039;, &#x5B;\\App\\Http\\Controllers\\Test::class, &#039;TestJob&#039;]);\n<\/pre><\/div>\n\n\n<h2 id=\"toc5\" class=\"wp-block-heading\">\u30b7\u30f3\u30d7\u30eb\u306a\u52d5\u4f5c\u78ba\u8a8d<\/h2>\n\n\n\n<h3 id=\"toc6\" class=\"wp-block-heading\">\u76ee\u7684<\/h3>\n\n\n\n<p>\u30b8\u30e7\u30d6\u3092\u30ad\u30e5\u30fc\u306b\u5165\u308c\u3066\u3001<\/p>\n\n\n\n<p>DB\u304c\u3069\u3046\u306a\u3063\u3066\u3044\u308b\u306e\u304b\u3092\u898b\u3066\u3001<\/p>\n\n\n\n<p>\u30ad\u30e5\u30fc\u306b\u5165\u308c\u305f\u30b8\u30e7\u30d6\u304c\u3069\u3046\u5b9f\u884c\u3055\u308c\u308b\u306e\u304b\u78ba\u8a8d\u3059\u308b\u3002<\/p>\n\n\n\n<h3 id=\"toc7\" class=\"wp-block-heading\">\u30b8\u30e7\u30d6\u3092\u30ad\u30e5\u30fc\u3078\u5165\u308c\u308b\u3002<\/h3>\n\n\n\n<p>http:\/\/localhost\u00a0\u30781\u56de\u30a2\u30af\u30bb\u30b9\u3057\u3066\u3001\u6b21\u306eSQL\u3092\u5b9f\u884c\u3059\u308b\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT * FROM jobs;\n<\/pre><\/div>\n\n\n<p>\u6b21\u306e\u3088\u3046\u306a\u7d50\u679c\u304c\u5f97\u3089\u308c\u308b\u306f\u305a\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>id<\/td><td>queue<\/td><td>peyload<\/td><td>attempts<\/td><td>reserved_at<\/td><td>available_at<\/td><td>created_at<\/td><\/tr><tr><td>\u6570\u5b57<\/td><td>default<\/td><td>{&#8220;uuid&#8221;:&#8221;bb78e2f3-13e5-4535-af52-645f2b65b4c0&#8243;,&#8221;displayName&#8221;:&#8221;App\\\\Jobs\\\\TestJob&#8221;,&#8221;job&#8221;:&#8221;Illuminate\\\\Queue\\\\CallQueuedHandler@call&#8221;,&#8221;maxTries&#8221;:null,&#8221;maxExceptions&#8221;:null,&#8221;failOnTimeout&#8221;:false,&#8221;backoff&#8221;:null,&#8221;timeout&#8221;:null,&#8221;retryUntil&#8221;:null,&#8221;data&#8221;:{&#8220;commandName&#8221;:&#8221;App\\\\Jobs\\\\TestJob&#8221;,&#8221;command&#8221;:&#8221;O:16:\\&#8221;App\\\\Jobs\\\\TestJob\\&#8221;:0:{}&#8221;}}<\/td><td>0<\/td><td>null<\/td><td>1745073256<\/td><td>1745073256<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>available_at\u3068created_at\u306e\u5024\u306fUNIX\u30bf\u30a4\u30e0\u30b9\u30bf\u30f3\u30d7\u306a\u306e\u3067\u3001\u5909\u63db\u3057\u3066\u898b\u3066\u3082\u3089\u3044\u305f\u3044\u304c\u3001available_at\u3068created_at\u306e\u5024\u304c\u540c\u4e00\u3067\u3042\u308b\u3053\u3068\u3092\u898b\u308c\u3070\u4f55\u3068\u306a\u304f\u7528\u9014\u304c\u308f\u304b\u308b\u306f\u305a\u3002<\/p>\n\n\n\n<p>\u3053\u306ejobs\u30c6\u30fc\u30d6\u30eb\u3078\u4e0a\u8a18\u306e\u3088\u3046\u306a\u30c7\u30fc\u30bf\u304c\u3042\u308c\u3070\u3001\u4f5c\u6210\u3055\u308c\u305f\u30b8\u30e7\u30d6\u304c\u30ad\u30e5\u30fc\u306b\u5165\u3063\u305f\u3068\u78ba\u8a8d\u3067\u304d\u308b\u3002<\/p>\n\n\n\n<h3 id=\"toc8\" class=\"wp-block-heading\">\u30ad\u30e5\u30fc\u306b\u5165\u3063\u3066\u3044\u308b\u30b8\u30e7\u30d6\u3092\u5b9f\u884c\u3059\u308b<\/h3>\n\n\n\n<p>\u30ad\u30e5\u30fc\u30ef\u30fc\u30ab\u3092\u8d77\u52d5\u3059\u308b\u305f\u3081\u306b\u6b21\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308c\u3070\u826f\u3044\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nphp artisan queue:work\n<\/pre><\/div>\n\n\n<p>\u6b21\u306e\u3088\u3046\u306b\u753b\u9762\u306b\u30b8\u30e7\u30d6\u304c\u5b9f\u884c\u3055\u308c\u305f\u65e8\u304c\u8868\u793a\u3055\u308c\u308b\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nINFO Processing jobs from the &#x5B;default] queue.\u00a0\n\n2025-04-19 15:17:05 App\\Jobs\\TestJob ........................................................... RUNNING\n\n2025-04-19 15:17:05 App\\Jobs\\TestJob ...................................................... 18.12ms DONE\n<\/pre><\/div>\n\n\n<p>\u307e\u305f\u3001\u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\uff08storage\/logs\/laravel.log\uff09\u3092\u898b\u308b\u3068\u6b21\u306e\u3088\u3046\u306a\u30ed\u30b0\u304c\u8a18\u9332\u3055\u308c\u3066\u3044\u308b\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&#x5B;2025-04-19 15:17:05] local.INFO: TestJob\n<\/pre><\/div>\n\n\n<p>jobs\u30c6\u30fc\u30d6\u30eb\u3092\u5148\u307b\u3069\u306eSQL\u3067\u78ba\u8a8d\u3059\u308b\u3068\u3001\u30c7\u30fc\u30bf\u306f\u7121\u304f\u306a\u3063\u3066\u3044\u308b\u3002<\/p>\n\n\n\n<h3 id=\"toc9\" class=\"wp-block-heading\">\u30ad\u30e5\u30fc\u30ef\u30fc\u30ab\u304c\u5b9f\u884c\u4e2d\u306b\u30b8\u30e7\u30d6\u3092\u30ad\u30e5\u30fc\u306b\u5165\u308c\u308b<\/h3>\n\n\n\n<p>\u4e0a\u8a18\u306eartisan\u30b3\u30de\u30f3\u30c9\u304c\u5b9f\u884c\u3055\u308c\u7d9a\u3051\u3066\u3044\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3057\u3066\u3001<\/p>\n\n\n\n<p>\u518d\u5ea6http:\/\/localhost\u3078\u30a2\u30af\u30bb\u30b9\u3057\u3001<\/p>\n\n\n\n<p>\u30b8\u30e7\u30d6\u3092\u30ad\u30e5\u30fc\u3078\u683c\u7d0d\u3059\u308b\u3068\u5373\u5b9f\u884c\u3055\u308c\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3059\u308c\u3070\u826f\u3044\u3002<\/p>\n\n\n\n<h2 id=\"toc10\" class=\"wp-block-heading\">\u30ec\u30fc\u30c8\u5236\u9650\u306e\u52d5\u4f5c\u78ba\u8a8d<\/h2>\n\n\n\n<p>\u8a66\u3057\u305f\u4e2d\u3067\u306f2\u30d1\u30bf\u30fc\u30f3\u306e\u4f7f\u3044\u65b9\u304c\u3067\u304d\u305d\u3046\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>1. \u6307\u5b9a\u3057\u305f\u6642\u9593\u3092\u7d4c\u904e\u3059\u308b\u305f\u3073\u306b\u30ad\u30e5\u30fc\u5185\u306e\u30b8\u30e7\u30d6\u30921\u500b\u5b9f\u884c\u3059\u308b\u3002\u305f\u3060\u3057\u3001\u30ad\u30e5\u30fc\u5185\u306e\u30b8\u30e7\u30d6\u306e\u6570\u3092\u628a\u63e1\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002<\/li>\n\n\n\n<li>2. \u6307\u5b9a\u3057\u305f\u6642\u9593\u3092\u7d4c\u904e\u3057\u306a\u3044\u3068\u30ad\u30e5\u30fc\u3078\u30b8\u30e7\u30d6\u3092\u8ffd\u52a0\u3067\u304d\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u3002\u30ad\u30e5\u30fc\u3078\u8ffd\u52a0\u3055\u308c\u305f\u30b8\u30e7\u30d6\u306f\u5373\u5b9f\u884c\u3055\u308c\u308b\u3002<\/li>\n<\/ol>\n\n\n\n<p><\/p>\n\n\n\n<h3 id=\"toc11\" class=\"wp-block-heading\">1\u756a\u76ee\u306e\u6307\u5b9a\u3057\u305f\u6642\u9593\u3092\u7d4c\u904e\u3059\u308b\u305f\u3073\u306b\u30ad\u30e5\u30fc\u5185\u306e\u30b8\u30e7\u30d6\u30921\u500b\u5b9f\u884c\u3059\u308b\u5834\u5408\u306e\u4f8b<\/h3>\n\n\n\n<p>\u524d\u63d0\uff1a\u4e0a\u8a18\u306e\u30b7\u30f3\u30d7\u30eb\u306a\u52d5\u4f5c\u78ba\u8a8d\u306e\u5185\u5bb9\u3092\u6d41\u7528\u3059\u308b\u3002<\/p>\n\n\n\n<p>TestJob.php \u306e\u5185\u5bb9\u3092\u6b21\u306e\u3088\u3046\u306b\u7de8\u96c6\u3059\u308b\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\n\nnamespace App\\Jobs;\n\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Foundation\\Queue\\Queueable;\nuse Illuminate\\Queue\\Middleware\\RateLimited;\nuse Illuminate\\Support\\Facades\\Log;\n\nclass TestJob implements ShouldQueue\n{\n    use Queueable;\n\n    public $tries = 0;\n    \/**\n     * Create a new job instance.\n     *\/\n    public function __construct()\n    {\n        \/\/\n    }\n\n    \/**\n     * Execute the job.\n     *\/\n    public function handle(): void\n    {\n        Log::info(&#039;TestJob&#039; . mt_rand(10, 20));\n    }\n\n    public function middleware(): array\n    {\n        return &#x5B;(new RateLimited(&#039;TestJob1min&#039;))];\n    }\n}\n<\/pre><\/div>\n\n\n<p><\/p>\n\n\n\n<p>app\/Providers\/AppServiceProvider.php \u306e\u5185\u5bb9\u3092\u6b21\u306e\u3088\u3046\u306b\u7de8\u96c6\u3059\u308b\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\n\nnamespace App\\Providers;\n\nuse Illuminate\\Cache\\RateLimiting\\Limit;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\RateLimiter;\nuse Illuminate\\Support\\ServiceProvider;\n\nclass AppServiceProvider extends ServiceProvider\n{\n    \/**\n     * Register any application services.\n     *\/\n    public function register(): void\n    {\n        \/\/\n    }\n\n    \/**\n     * Bootstrap any application services.\n     *\/\n    public function boot(): void\n    {\n        RateLimiter::for(&#039;TestJob1min&#039;, function() {\n            \/\/ 15\u79d2\u306b1\u56de\u3057\u304b\u8a31\u53ef\u3057\u306a\u3044\u3002\n            return Limit::perSecond(1, 15);\n        });\n    }\n}\n<\/pre><\/div>\n\n\n<p><\/p>\n\n\n\n<p>\u4e0a\u8a18\u5185\u5bb9\u3067http:\/\/localhost\u30783\u56de\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u3001<\/p>\n\n\n\n<p>\u5404\u30b8\u30e7\u30d6\u306e\u51e6\u7406\u304c15 + \u03b1\u79d2\u3067\u5b9f\u884c\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u308b\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 id=\"toc12\" class=\"wp-block-heading\">2\u756a\u76ee\u306e\u6307\u5b9a\u3057\u305f\u6642\u9593\u3092\u7d4c\u904e\u3057\u306a\u3044\u3068\u30ad\u30e5\u30fc\u3078\u30b8\u30e7\u30d6\u3092\u8ffd\u52a0\u3067\u304d\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u5834\u5408\u306e\u4f8b<\/h3>\n\n\n\n<p>\u524d\u63d0\uff1a\u4e0a\u8a18\u306e\u30b7\u30f3\u30d7\u30eb\u306a\u52d5\u4f5c\u78ba\u8a8d\u306e\u5185\u5bb9\u3092\u6d41\u7528\u3059\u308b\u3002<\/p>\n\n\n\n<p>\u524d\u63d02\uff1a\u4e0a\u8a18\u306eAppServiceProvider.php \u306e\u5185\u5bb9\u3092\u6d41\u7528\u3059\u308b\u3002<\/p>\n\n\n\n<p>TestJob.php \u306e\u5185\u5bb9\u3092\u6b21\u306e\u3088\u3046\u306b\u7de8\u96c6\u3059\u308b\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\n\nnamespace App\\Jobs;\n\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Foundation\\Queue\\Queueable;\nuse Illuminate\\Queue\\Middleware\\RateLimited;\nuse Illuminate\\Support\\Facades\\Log;\n\nclass TestJob implements ShouldQueue\n{\n    use Queueable;\n\n    \/**\n     * Create a new job instance.\n     *\/\n    public function __construct()\n    {\n        \/\/\n    }\n\n    \/**\n     * Execute the job.\n     *\/\n    public function handle(): void\n    {\n        Log::info(&#039;TestJob&#039; . mt_rand(10, 20));\n    }\n\n    public function middleware(): array\n    {\n        return &#x5B;(new RateLimited(&#039;TestJob1min&#039;))-&gt;dontRelease()];\n    }\n}\n<\/pre><\/div>\n\n\n<p><\/p>\n\n\n\n<p>\u4e0a\u8a18\u5185\u5bb9\u3067http:\/\/localhost\u307815\u79d2\u4ee5\u5185\u306b3\u56de\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u3001<\/p>\n\n\n\n<p>\u30b8\u30e7\u30d6\u306f1\u500b\u3057\u304b\u5b9f\u884c\u3055\u308c\u305a\u3001\u30ad\u30e5\u30fc\u5185\uff08jobs\u30c6\u30fc\u30d6\u30eb\uff09\u306e\u30b8\u30e7\u30d6\u306f0\u500b\u3068\u306a\u3063\u3066\u3044\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u308b\u3002<\/p>\n\n\n\n<p>\u305d\u306e15\u79d2\u5f8c\u306b\u518d\u5ea6\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u3001\u30b8\u30e7\u30d6\u306f\u307e\u305f1\u500b\u5b9f\u884c\u3055\u308c\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u308b\u3002<\/p>\n\n\n\n<h2 id=\"toc13\" class=\"wp-block-heading\">\u4e00\u610f\u306a\u30b8\u30e7\u30d6\u306e\u52d5\u4f5c\u78ba\u8a8d<\/h2>\n\n\n\n<p>\u30ad\u30e5\u30fc\u5185\u3067$uniqueId\u304c\u6307\u5b9a\u3055\u308c\u305f\u30b8\u30e7\u30d6\u304c\u3042\u308b\u5834\u5408\u3001\u540c\u4e00\u306e$uniqueId\u3092\u6301\u3064\u30b8\u30e7\u30d6\u3092\u65b0\u305f\u306b\u8ffd\u52a0\u3067\u304d\u306a\u304f\u306a\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3059\u308b\u3002<\/p>\n\n\n\n<p>\uff08\u30ad\u30e5\u30fc\u5185\u3067$uniqueId\u304c\u6307\u5b9a\u3055\u308c\u305f\u30b8\u30e7\u30d6\u306f\u3001$uniqueId\u306b\u57fa\u3065\u3044\u3066\u4e00\u610f\u306e\u3082\u306e\u3068\u306a\u308b\u3002\uff09<\/p>\n\n\n\n<p>\u30ec\u30fc\u30c8\u5236\u9650\u306e\u52d5\u4f5c\u78ba\u8a8d\u306e<\/p>\n\n\n\n<p>1\u756a\u76ee\u306e\u6307\u5b9a\u3057\u305f\u6642\u9593\u3092\u7d4c\u904e\u3059\u308b\u305f\u3073\u306b\u30ad\u30e5\u30fc\u5185\u306e\u30b8\u30e7\u30d6\u30921\u500b\u5b9f\u884c\u3059\u308b\u3001\u3092\u6d41\u7528\u3057\u3066\u78ba\u8a8d\u3059\u308b\u3002<\/p>\n\n\n\n<p>Test\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u306eTestJob\u30e1\u30bd\u30c3\u30c9\u306e\u5185\u5bb9\u3092\u6b21\u306e\u3088\u3046\u306b\u7de8\u96c6\u3059\u308b\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\npublic function TestJob(Request $request)\n    {\n        TestJob::dispatch(100);\n        return view(&#039;welcome&#039;);\n    }\n<\/pre><\/div>\n\n\n<p><\/p>\n\n\n\n<p>TestJob.php \u306e\u5185\u5bb9\u3092\u6b21\u306e\u3088\u3046\u306b\u7de8\u96c6\u3059\u308b\u3002<\/p>\n\n\n\n<p>ShouldBeUnique\u306e\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u3092\u8ffd\u52a0\u3057\u3066\u3044\u308b\u70b9\u306b\u6ce8\u610f\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\n\nnamespace App\\Jobs;\n\nuse Illuminate\\Contracts\\Queue\\ShouldBeUnique;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Foundation\\Queue\\Queueable;\nuse Illuminate\\Queue\\Middleware\\RateLimited;\nuse Illuminate\\Support\\Facades\\Log;\n\nclass TestJob implements ShouldQueue, ShouldBeUnique\n{\n    use Queueable;\n\n    public $tries = 0;\n    public $uniqueId;\n\n    \/**\n     * Create a new job instance.\n     *\/\n    public function __construct(int $intValue)\n    {\n        Log::info(&quot;TestJob Constructor \\$intValue = {$intValue}&quot;);\n        $this-&gt;uniqueId = $intValue;\n    }\n\n    \/**\n     * Execute the job.\n     *\/\n    public function handle(): void\n    {\n        Log::info(&#039;TestJob&#039; . mt_rand(10, 20));\n    }\n\n    public function middleware(): array\n    {\n        return &#x5B;(new RateLimited(&#039;TestJob1min&#039;))];\n    }\n}\n<\/pre><\/div>\n\n\n<p><\/p>\n\n\n\n<p>\u4e0a\u8a18\u5185\u5bb9\u3067http:\/\/localhost\u307815\u79d2\u4ee5\u5185\u306b3\u56de\u4ee5\u4e0a\u30a2\u30af\u30bb\u30b9\u3057\u3066\u3082\u3001<\/p>\n\n\n\n<p>\u30b8\u30e7\u30d6\u306f2\u56de\u3057\u304b\u5b9f\u884c\u3055\u308c\u306a\u3044\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u308b\u3002<\/p>\n\n\n\n<p>1\u56de\u76ee\u306f\u30ad\u30e5\u30fc\u3078\u5165\u308c\u305f\u77ac\u9593\u5b9f\u884c\u3055\u308c\u3001<\/p>\n\n\n\n<p>2\u56de\u76ee\u306f\u4e00\u610f\u3067\u3042\u308b\u305f\u3081\u30ad\u30e5\u30fc\u3078\u5165\u308c\u308b\u3053\u3068\u304c\u3067\u304d\u3001<\/p>\n\n\n\n<p>3\u56de\u76ee\u4ee5\u964d\u306f$uniqueId\u304c\u540c\u4e00\u3067\u3042\u308b\u30b8\u30e7\u30d6\u304c\u3001\u30ad\u30e5\u30fc\u5185\u306b\u5b58\u5728\u3059\u308b\u305f\u3081\u30ad\u30e5\u30fc\u3078\u5165\u308c\u308b\u3053\u3068\u304c\u3067\u304d\u306a\u3044\u3002<\/p>\n\n\n\n<h2 id=\"toc14\" class=\"wp-block-heading\">Tips<\/h2>\n\n\n\n<h3 id=\"toc15\" class=\"wp-block-heading\">\u30ad\u30e5\u30fc\u5185\u306e\u30b8\u30e7\u30d6\u6570\u3092\u53d6\u5f97<\/h3>\n\n\n\n<p>DB\u304b\u3089\u76f4\u63a5\u53d6\u5f97\u3057\u3066\u3082\u826f\u3044\u304b\u3082\u3057\u308c\u306a\u3044\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\nuse Illuminate\\Support\\Facades\\Queue;\n\nQueue::size(&#039;default&#039;);\n<\/pre><\/div>\n\n\n<h3 id=\"toc16\" class=\"wp-block-heading\">\u30b8\u30e7\u30d6\u306b\u8a2d\u5b9a\u3057\u305funiqueId\u3092\u53d6\u5f97<\/h3>\n\n\n\n<p>DB\u304b\u3089\u5f15\u3063\u5f35\u308b\u3084\u308a\u65b9\u306b\u306a\u308b\u3002<\/p>\n\n\n\n<p>\u30ad\u30e5\u30fc\u306b1\u500b\u306e\u30b8\u30e7\u30d6\u304c\u3042\u308b\u72b6\u614b\u3067\u5b9f\u884c\u3059\u308b\u4f8b\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n$dbResult = DB::table(&#039;jobs&#039;)-&gt;select(&#039;payload&#039;)-&gt;get();\n\n$uniqueId = unserialize(json_decode($dbResult-&gt;all()&#x5B;0]-&gt;payload)-&gt;data-&gt;command)-&gt;uniqueId;\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>\u524d\u63d0 Laravel\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\uff1a11.20.0 \u30ad\u30e5\u30fc\u306e\u5185\u5bb9\u306fDB\u306b\u4fdd\u5b58\u3059\u308b\u8a2d\u5b9a\u3067\u3001\u5fc5\u8981\u306a\u30c6\u30fc\u30d6\u30eb\u3082\u30de\u30a4\u30b0\u30ec\u30fc\u30c8\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u3092\u524d\u63d0\u3068\u3059\u308b\u3002 \uff08\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u72b6\u614b\u3067\u30de\u30a4\u30b0\u30ec\u30fc\u30c8\u3059\u308c\u3070\u305d\u3046\u306a\u3063\u3066\u3044\u308b\u306f\u305a\uff09 \u5168\u4f53\u7684\u306a\u6ce8\u610f\u70b9\u3068 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[96],"tags":[88,81],"class_list":["post-1283","post","type-post","status-publish","format-standard","hentry","category-laravel","tag-laravel","tag-php"],"_links":{"self":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/1283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1283"}],"version-history":[{"count":7,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/1283\/revisions"}],"predecessor-version":[{"id":1290,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/1283\/revisions\/1290"}],"wp:attachment":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}