                                        {"id":7003,"date":"2024-04-02T21:05:29","date_gmt":"2024-04-02T21:05:29","guid":{"rendered":"https:\/\/eservices360.com\/?p=7003"},"modified":"2024-04-02T21:10:27","modified_gmt":"2024-04-02T21:10:27","slug":"the-fitting-technique-to-run-laravel-queue-worker-in-manufacturing","status":"publish","type":"post","link":"https:\/\/eservices360.com\/resources\/the-fitting-technique-to-run-laravel-queue-worker-in-manufacturing\/","title":{"rendered":"The becoming approach to run laravel queue employee in manufacturing?"},"content":{"rendered":"<div>\n<div class=\"hu hv hw hx hy\">\n<div class=\"speechify-ignore ab co\">\n<div class=\"speechify-ignore bg l\">\n<div class=\"hz ia ib ic id ab\">\n<div>\n<div class=\"ab ie\">\n<div>\n<div class=\"bl\" aria-hidden=\"false\">\n<div class=\"l if ig bx ih ii\">\n<div class=\"l fi\">Queues are primarily essentially the most useful factor in laravel after we&#8217;re coping with jobs which take longer time to complete on account of no individual must attend.<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<pre class=\"oa ob oc od oe of og oh bo oi ba bj\"><span class=\"oj ok gt og b bf ol om l on oo\">    if ($checkCurrentRunnigGame) \nreturn once more()-&gt;with('error', 'Recreation is already working.');\n<\/span><\/pre>\n<p>dispatch(new RunGameJob)-&gt;onQueue(&#8216;default&#8217;);<\/p>\n<p>return redirect()-&gt;to(&#8216;dashboard&#8217;)<br \/>\n-&gt;with(&#8216;success&#8217;, &#8216;Recreation start effectively.&#8217;);<\/p>\n<p id=\"cf35\" class=\"pw-post-body-paragraph nc nd gt ne b nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv nw nx ny nz gm bj\">As an illustration, the job \u201cRunGameJob\u201d takes e.g. 2 minutes so no individual wants their browser to attend for 2 minutes everybody wants 250ms and why not? So we use queues proper right here which take care of the roles throughout the background and later and the best way lots later? That&#8217;s an fascinating question. I will reply this nevertheless first, we see how we run queue worker.<\/p>\n<pre class=\"oa ob oc od oe of og oh bo oi ba bj\"><span id=\"e7ab\" class=\"oj ok gt og b bf ol om l on oo\">php artisan queue:work<\/span><\/pre>\n<p id=\"2360\" class=\"pw-post-body-paragraph nc nd gt ne b nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv nw nx ny nz gm bj\">This command runs the queue worker and the queue worker instantly checks for any jobs throughout the jobs desk and runs these jobs.<\/p>\n<figure class=\"oa ob oc od oe ms mk ml paragraph-image\">\n<div class=\"mt mu fi mv bg mw\" tabindex=\"0\" role=\"button\">\n<div class=\"mk ml op\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-7131\" src=\"https:\/\/eservices360.com\/wp-content\/uploads\/2024\/03\/queue-worker-start-command.webp\" alt=\"\" width=\"720\" height=\"111\" srcset=\"https:\/\/eservices360.com\/resources\/wp-content\/uploads\/2024\/03\/queue-worker-start-command.webp 720w, https:\/\/eservices360.com\/resources\/wp-content\/uploads\/2024\/03\/queue-worker-start-command-300x46.webp 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/div>\n<\/div><figcaption class=\"my fe mz mk ml na nb be b bf z dt\">queue worker start command<\/figcaption><\/figure>\n<p id=\"4905\" class=\"pw-post-body-paragraph nc nd gt ne b nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv nw nx ny nz gm bj\">Suppose you run this throughout the terminal and in the intervening time there usually are not any jobs throughout the jobs desk so the queue worker sits and waits for the job. This works high-quality until we shut the terminal on account of in manufacturing we&#8217;re capable of\u2019t sit for our complete life opening that terminal. Now we&#8217;ve got completely different points to do. There are two choices to resolve this downside.<\/p>\n<ol class=\"\">\n<li id=\"f4e3\" class=\"nc nd gt ne b nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv nw nx ny nz oq or os bj\">Cron Job<\/li>\n<li id=\"3550\" class=\"nc nd gt ne b nf ot nh ni nj ou nl nm nn ov np nq nr ow nt nu nv ox nx ny nz oq or os bj\">Supervisor<\/li>\n<\/ol>\n<p id=\"3ae1\" class=\"pw-post-body-paragraph nc nd gt ne b nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv nw nx ny nz gm bj\">First, we&#8217;re going to focus on regarding the cron job. This function runs that queue worker command after some time. It\u2019s as a lot as you the best way lots time you want to wait your client to get data. As an illustration, if the admin begins the game \u201cRunGameJob\u201d and likewise you want to run that job instantly with none delay.<\/p>\n<pre class=\"oa ob oc od oe of og oh bo oi ba bj\"><span id=\"e9db\" class=\"oj ok gt og b bf ol om l on oo\">Artisan::command('queue:worker')-&gt;everyMinute();<\/span><\/pre>\n<p id=\"e4bb\" class=\"pw-post-body-paragraph nc nd gt ne b nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv nw nx ny nz gm bj\">It&#8217;ll run the queue worker every minute this method is good nevertheless one drawback is concurrency Factors: If the queue worker is already processing jobs when the scheduled command is executed as soon as extra, it might finish in concurrency factors. A variety of instances of the queue worker may be making an attempt to course of the similar job concurrently, leading to shocking behaviour or errors.<\/p>\n<p id=\"67d7\" class=\"pw-post-body-paragraph nc nd gt ne b nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv nw nx ny nz gm bj\">So there could also be one different resolution to take care of this case which is supervisor. The supervisor is an working system issue, not a laravel issue. So take observe now we&#8217;re using an working system to resolve our downside. Let\u2019s rephrase our requirement in straightforward phrases sooner than leaping in.<\/p>\n<p id=\"903a\" class=\"pw-post-body-paragraph nc nd gt ne b nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv nw nx ny nz gm bj\"><strong class=\"ne gu\">We want that queue worker to run and if it stops then restart it.<\/strong><\/p>\n<p id=\"4435\" class=\"pw-post-body-paragraph nc nd gt ne b nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv nw nx ny nz gm bj\">To place in Supervisor in your server, you probably can take advantage of two methods:<\/p>\n<p id=\"ca56\" class=\"pw-post-body-paragraph nc nd gt ne b nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv nw nx ny nz gm bj\">1. Benefit from the terminal immediately on the web server.<br \/>\n2. Make use of SSH to entry and arrange Supervisor.<\/p>\n<pre class=\"oa ob oc od oe of og oh bo oi ba bj\"><span id=\"c073\" class=\"oj ok gt og b bf ol om l on oo\">sudo apt-get arrange supervisor<\/span><\/pre>\n<p id=\"34e8\" class=\"pw-post-body-paragraph nc nd gt ne b nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv nw nx ny nz gm bj\">It&#8217;ll arrange the supervisor in your server.<\/p>\n<p id=\"e16c\" class=\"pw-post-body-paragraph nc nd gt ne b nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv nw nx ny nz gm bj\">Subsequent, generate a file named laravel-worker.conf contained in the \/and so forth\/supervisor\/conf.d itemizing. It\u2019s best to remain to this convention when naming directories and knowledge, nevertheless you probably can change them if wished.<\/p>\n<p id=\"f232\" class=\"pw-post-body-paragraph nc nd gt ne b nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv nw nx ny nz gm bj\">Content material materials to write down down throughout the file are:<\/p>\n<pre class=\"oa ob oc od oe of og oh bo oi ba bj\"><span class=\"oj ok gt og b bf ol om l on oo\">[program:laravel-worker]\nprocess_name=%(program_name)s_%(process_num)02d<\/span><\/pre>\n<p>command=php \/\/pathto your endeavor\/\/ \/artisan queue:work<\/p>\n<p>autostart=true<br \/>\nautorestart=true<br \/>\nstopasgroup=true<br \/>\nkillasgroup=true<\/p>\n<p>client= \/\/ username in keeping with you probably root\/\/<\/p>\n<p>numprocs=1<br \/>\nredirect_stderr=true<br \/>\nstdout_logfile=\/home\/forge\/app.com\/worker.log<br \/>\nstopwaitsecs=3600<br \/>\nstdout_logfile=\/var\/log\/laravel-worker.log<\/p>\n<p id=\"16bc\" class=\"pw-post-body-paragraph nc nd gt ne b nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv nw nx ny nz gm bj\">The supplied content material materials have to be written into the laravel-worker.conf file, save, after which execute the following directions:<\/p>\n<pre class=\"oa ob oc od oe of og oh bo oi ba bj\"><span class=\"oj ok gt og b bf ol om l on oo\">sudo supervisorctl reread<\/span><\/pre>\n<p>sudo supervisorctl exchange<\/p>\n<p>sudo supervisorctl start &#8220;laravel-worker:*&#8221;<\/p>\n<p id=\"d74a\" class=\"pw-post-body-paragraph nc nd gt ne b nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv nw nx ny nz gm bj\">Undoubtedly.<\/p>\n<p id=\"1b7a\" class=\"pw-post-body-paragraph nc nd gt ne b nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv nw nx ny nz gm bj\">Be at liberty to proceed. Nonetheless, whenever you encounter any exceptions, on account of there are on a regular basis exceptions. One such exception might very properly be &#8220;laravel-worker: ERROR (no such group).&#8221;<\/p>\n<p id=\"2d81\" class=\"pw-post-body-paragraph nc nd gt ne b nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv nw nx ny nz gm bj\">It&#8217;ll occur in case your supervisor unable to detect your \u201claravel-worker.conf\u201d file. To unravel this downside add the beneath code to supervisord.conf file which is located in \/and so forth itemizing almost certainly.<\/p>\n<pre class=\"oa ob oc od oe of og oh bo oi ba bj\"><span id=\"3f88\" class=\"oj ok gt og b bf ol om l on oo\">[include]\ndata = supervisor\/conf.d\/*.conf<\/span><\/pre>\n<p id=\"d0e0\" class=\"pw-post-body-paragraph nc nd gt ne b nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv nw nx ny nz gm bj\"><span>Enjoy and keep coding \u2764\ufe0f<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Queues are primarily essentially the most useful factor in laravel after we&#8217;re coping with jobs which take longer time to complete on account of no individual must attend. if ($checkCurrentRunnigGame) return once more()-&gt;with(&#8216;error&#8217;, &#8216;Recreation is already working.&#8217;); dispatch(new RunGameJob)-&gt;onQueue(&#8216;default&#8217;); return redirect()-&gt;to(&#8216;dashboard&#8217;) -&gt;with(&#8216;success&#8217;, &#8216;Recreation start effectively.&#8217;); As an illustration, the job \u201cRunGameJob\u201d takes e.g. 2 minutes [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":7004,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[94],"tags":[102,110,112,104,98,103,106],"class_list":["post-7003","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-laravel","tag-php-error-handling","tag-php-extensions","tag-php-functions","tag-php-version-updates","tag-symfony","tag-zend-framework"],"blog_post_layout_featured_media_urls":{"thumbnail":["https:\/\/eservices360.com\/resources\/wp-content\/uploads\/2024\/03\/1OmJyzATj10ONTXur9BxDgA-150x150.jpeg",150,150,true],"full":["https:\/\/eservices360.com\/resources\/wp-content\/uploads\/2024\/03\/1OmJyzATj10ONTXur9BxDgA.jpeg",1200,600,false]},"categories_names":{"94":{"name":"PHP","link":"https:\/\/eservices360.com\/resources\/category\/php\/"}},"tags_names":{"102":{"name":"Laravel","link":"https:\/\/eservices360.com\/resources\/tag\/laravel\/"},"110":{"name":"PHP Error Handling","link":"https:\/\/eservices360.com\/resources\/tag\/php-error-handling\/"},"112":{"name":"PHP Extensions","link":"https:\/\/eservices360.com\/resources\/tag\/php-extensions\/"},"104":{"name":"PHP Functions","link":"https:\/\/eservices360.com\/resources\/tag\/php-functions\/"},"98":{"name":"PHP Version Updates","link":"https:\/\/eservices360.com\/resources\/tag\/php-version-updates\/"},"103":{"name":"Symfony","link":"https:\/\/eservices360.com\/resources\/tag\/symfony\/"},"106":{"name":"Zend Framework","link":"https:\/\/eservices360.com\/resources\/tag\/zend-framework\/"}},"comments_number":"0","_links":{"self":[{"href":"https:\/\/eservices360.com\/resources\/wp-json\/wp\/v2\/posts\/7003","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eservices360.com\/resources\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eservices360.com\/resources\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eservices360.com\/resources\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/eservices360.com\/resources\/wp-json\/wp\/v2\/comments?post=7003"}],"version-history":[{"count":8,"href":"https:\/\/eservices360.com\/resources\/wp-json\/wp\/v2\/posts\/7003\/revisions"}],"predecessor-version":[{"id":7140,"href":"https:\/\/eservices360.com\/resources\/wp-json\/wp\/v2\/posts\/7003\/revisions\/7140"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/eservices360.com\/resources\/wp-json\/wp\/v2\/media\/7004"}],"wp:attachment":[{"href":"https:\/\/eservices360.com\/resources\/wp-json\/wp\/v2\/media?parent=7003"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eservices360.com\/resources\/wp-json\/wp\/v2\/categories?post=7003"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eservices360.com\/resources\/wp-json\/wp\/v2\/tags?post=7003"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}