Android
Affordable OnePlus N200 5G will go on sale on June 25th
The OnePlus N200 is one of the least expensive 5G phones to go on sale in the US. | Image: OnePlus OnePlus has confirmed that the inexpensive Nord N200 5G will be available in the Read more…
Android
The Realme GT lays claim to OnePlus’ ‘flagship killer’ mantle
Realme is launching its highest-end phone yet in several European countries today, describing it as a “flagship killer.” The Realme GT is a high-end device with a fast Qualcomm processor, a smooth OLED screen, and Read more…
PHP
What's new in laravel-event-sourcing v5
[AdSense-A]
Last week we released a new version of spatie/laravel-event-sourcing. Version 5 is probably one of the largest releases since the beginning of the package. We've worked several months on it and have been testing it extensively already in our own projects.
In this post, my colleague Brent will walk you through all the changes and new functionalities.
(more…)Android
YouTube is banning alcohol, gambling, and politics from its ‘most prominent’ ad slot
An example of the YouTube masthead ad. YouTube will no longer be accepting ads relating to alcohol, gambling, politics, or “prescription drug terms” for its masthead ad slot, which appears at the top of the Read more…
Android
Build sophisticated search features with AppSearch
Posted by Dan Saadati, Software Engineer, and Hanaa ElAzizi, Technical Program Manager Introducing AppSearch in Jetpack, now available in Alpha. AppSearch is an on-device search library which provides high performance and feature-rich full-text search functionality. Read more…
Android
Asus launches $499.99 Chromebook Flip CM5 with AMD Ryzen 5 processors
Asus Asus has released its latest Ryzen-powered Chromebook, the Chromebook Flip CM5. The CM5 has a 15.6-inch screen, and Asus is pushing it as a device for cloud-based gaming. It’s available now at Abt and Read more…
PHP
★ A Laravel package to dispatch jobs via Artisan
[AdSense-A]
Our team has released a new Laravel package: spatie/laravel-artisan-dispatchable. This package allows you to dispatch any job from an artisan command.
In this blog post, I'd like to explain why we created the package and how you can use it.
Why we created this package #
Laravel's scheduler will perform all tasks sequentially. When you add a scheduled task to the scheduler, the task should perform its work as fast as possible, so no other tasks will have to wait.
If you have a task that needs to run every minute and its runtime is close to a minute, you should not use a simple Artisan command, as this will result in the delay of all other minute-ly tasks.
Long-running tasks should be performed by jobs that perform their work on the queue. Laravel has the ability to schedule queued jobs. This way, those tasks will not block the scheduler.
$schedule->job(new ProcessPodcast)->everyFiveMinutes();
The downside of this approach is that you cannot run that job via Artisan anymore. You have to choose between using an artisan command + blocking the scheduler on the one hand, and job + not blocking the scheduler on the other hand.
Using our package, you don't have to make that choice anymore. When letting your job implement SpatieArtisanDispatchableJobsArtisanDispatchable
, you will not block the scheduler and can still execute the logic via Artisan.
How to make jobs dispatchable via Artisan #
All you need to do is let your job implement the empty ArtisanDispatchable
interface.
use SpatieArtisanDispatchableJobsArtisanDispatchable;
class ProcessPodcast implements ArtisanDispatchable
{
public function handle()
{
// perform some work...
}
}
This allows the job to be executed via Artisan using the kebab-case version of the base class name.
php artisan process-podcast
This job will not be queued but will be immediately executed inside the executed artisan command.
If you want to put your job on the queue instead of executing it immediately, add the queued
option.
php artisan process-podcast --queued
If your job has constructor arguments, you can still use the package. Constructor arguments can be passed as options to the artisan command. If a constructor argument is an Eloquent model, you may pass the model's id to the artisan command option.
Here's an example:
use App<span class="hljs-title">Models<span class="hljs-title">Podcast;
use Spatie<span class="hljs-title">ArtisanDispatchable<span class="hljs-title">Jobs<span class="hljs-title">ArtisanDispatchable;
class ProcessPodcast implements ArtisanDispatchable
{
public function __construct(
Podcast $podcast,
) {}
<span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handle</span><span class="hljs-params">()</span>
</span>{
<span class="hljs-comment">// perform some work...</span>
}
}
Here's how you can execute this job with podcast id 1234
php artisan process-podcast --podcast=1234
In closing #
This package has a few other whistles and bells, which are explained in the package's readme on GitHub.
This isn't the first package our team has created. Check our website for an extensive list of things we released previously.
If you want to support our open source work, consider picking up one of our premium products and courses.
(more…)PHP
Alpine 3.x Tips and Tricks
Here are a few tips and tricks that you can use in your Alpine 3.x components. Read More
Android
Google Workspace and Google Chat are officially available to everybody
Google is announcing some changes to its Workspace suite of apps and services today, including availability for anybody who has a Google account. Google says that there are over three billion users of its Workspace Read more…