-
-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dispatch jobs without relating to models #33
Dispatch jobs without relating to models #33
Conversation
fe4240f
to
1f5ee27
Compare
This reverts commit 53d0968.
* Bump dependencies for Laravel 10 * Update GitHub Actions for Laravel 10 * Update run-tests.yml * Update composer.json --------- Co-authored-by: Mateus Junges <mateus@junges.dev>
…ut-relating-to-models # Conflicts: # composer.json # src/Concerns/Trackable.php # src/Models/TrackedJob.php
Hey @mateusjunges There is also a bug with Function Thats the quick fix for class NewTrackedJobMiddleware
{
public function handle(object $job, Closure $next): void
{
// echo 'Attempts # ' . $job->job->attempts() . PHP_EOL;
// echo 'Job ID # ' . $job->job->getJobId() . PHP_EOL;
if ($job->job->attempts() > 1)
{
if ($job->trackedJob->status !== TrackedJob::STATUS_RETRYING) // Avoid an unnecessary DB writes.
{
$job->trackedJob->markAsRetrying();
}
} else
{
$job->trackedJob->markAsStarted();
}
$response = $next($job);
... |
Hey @DimaVIII 👋 I'm quite out of time to work on it right now, that's why it is paused. I plan to ship it on v2, as soon as I have the time to go back to it 🙂 |
Hey @mateusjunges ! Based on this PR I added all the mentioned features and fixed all bug, I also added tests for all new features that I implemented. I'm still testing and a bit more clean up is missing, so haven't pushed the the PR yet. Things to consider
A small preview on how it looks like implemented into a frontend. |
@mateusjunges is it possible to get a new release that includes these changes? 🙏 |
This PR changes how relating a tracked job to a model works.
In v1, you must add a
Illuminate\Database\Eloquent\Model
instance as the first parameter of your's job constructor, which will be used to track the job and relate it to the given model. In this PR, I changed this behavior to have no related models by default.You can define the new
trackableKey
andtrackableType
methods in your job class if you need to relate your job to any given model.For example, if you define these two methods:
the
TrackedJob
instance will be created using the podcast id astrackable_id
and the podcast model FQCN (or any relation morph map you have defined) as thetrackable_type
.