VS Code and Laravel Tasks

Several of my recent projects are Laravel apps that use Horizon to manage the queue and run jobs.

However, I frequently forgot to run php artisan horizon when opening the project, and sometimes spent a bit of time trying to figure out why a job hadn’t run before remembering. 🤦

In addition—and this is a relatively minor annoyance—even when I do remember to start Horizon, sometimes I’d like to see the metrics dashboard showing how many jobs have run in the past few minutes.

Edit: I added npm run dev to help with Tailwind JIT mode and Vite asset building.

Workspace Tasks

Enter VS Code’s Tasks feature. This can automatically start running tasks when a workspace is opened.

To get set up:

  1. If you haven’t yet, go to File > Save Workspace As… and save a workspace config file to somewhere on your hard drive
  2. Open the command palette (command-shift-P) and activate “Tasks: Manage Automatic Tasks in Folder”
  3. Activate “Allow Automatic Tasks”
  4. Open the command palette again and activate “Workspaces: Open Workspace Configuration File”
  5. Add the following to the workspace config file:

Now every time I open the workspace, assets are rebuilt as I modify them; Horizon, Pulse, and the scheduler start running automatically; and stale logs and failed jobs are pruned, keeping my database at a manageable size.