The right place to inject a service into a queued job
Let’s take a look at this job:
Page 2 of 76 - keep going...
Let’s take a look at this job:
Maybe I’m behind. But I like to think of it as conservative. Parallel unit testing has been around for a while, and I haven’t really reached for it until recently.
This isn’t about not wanting to change, though. It’s about using the proper tools for the job, and only when necessary.
Or at least, that’s how I rationalize my delay. But maybe you’re in the same place. Let’s dig into why I waited, why you might want to wait still, and the reasons why this works now.
Sometimes I look back at my older open source work, or talks, and feel a little bit ashamed.
“That’s not right.” “That’s not how you’d do it” (or not how I’d do it now).
And the times I re-invented the wheel when packages were already there…
As embarrassing as that seems now, there was a good reason for that.
Doing things that others have done, but in our own way, is a synthesis that helps us learn.
Let’s not forget about that.
Pennant defaults to the database driver, and most tutorials follow that lead. That’s fine for long-lived flags, but it adds a row and a query for every feature resolution.
Laravel’s default behavior on a failed FormRequest validation is to throw a ValidationException, which the framework’s exception handler converts into a redirect to the previous URL with the input flashed to the session and errors attached.
That works perfectly when a person submits the form as the redirect lands them back on that page with the errors.
It breaks down when the form submits itself, for example a bookmark to a GET form with validation, or submitting something into a target="_blank" (like PDF generation).
When you think of a CTO, what do you see?
Someone gray-haired, steering the ship like the last 20 years? A young, hot-shot that solves every single technical problem and then plays video games to relax?
It really doesn’t matter. I don’t actually picture or “see” anyone.
I can tell if a real CTO is in the room by just opening up my ears.
Laravel gives you two ways to define translations, PHP array files with short keys, or JSON files where the key is the default string itself. Array files are nice when you want stable, namespaced keys you reference everywhere. JSON files are nice when you don’t want to invent a key for every string and you’d rather just write the English (or default) version inline.
I picked JSON on a recent project, and then I hit a moment that gave me pause. I needed pluralization.
Most Eloquent factory states I’ve created are pretty simple like ->published() or ->cancelled().
They flip a flag or override a field to a fixed value making the call site of the factory easier to understand and requiring less ceremony.
Awesome.
But, a state can also accept arguments, and that opens up some useful patterns like deriving values from another model passed in by the caller.
In tests, it’s common to have a service that takes an Eloquent model as an argument, and therefore you want to mock that service to confirm it was called with the right model instance.
It’s already hard enough for me to start my exercise in the morning. Any friction in the way can make me stop it - or at least not track it.
Since I started using Strava to track my walks, I checked its iOS widgets. I figured I should be able to just click a widget to start an activity.
Sadly that’s not the case. They’re only progress widgets. So, after doing some research, I created my own iOS shortcut. Here’s how.