Introduction
We're enhancing our devlog-ist/landing project, which provides developer logs, with a new feature to improve data capture. This involves adding a mechanism to synchronize all owned repositories, ensuring a complete commit and pull request history is available.
The Challenge
Previously, fetching the complete history of commits and pull requests across all owned repositories was a manual and time-consuming task. Developers needed a more automated and comprehensive way to gather this data for analysis and reporting.
The Solution
We've introduced a new "Sync All Owned Repositories" button. This button triggers a background job for each owned GitHub repository, fetching all historical commits and user-authored pull requests without any date limitations. To manage the parallelism and potential failures, we're leveraging Bus::batch.
use Illuminate\Support\Facades\Bus;
class RepositorySyncService
{
public function syncAllRepositories(array $repositories)
{
$batches = Bus::batch(function () use ($repositories) {
foreach ($repositories as $repo) {
yield new SyncRepositoryJob($repo);
}
})->allowFailures()->dispatch();
return $batches;
}
}
This code snippet illustrates how Bus::batch is used to dispatch multiple SyncRepositoryJob instances, one for each repository. The allowFailures() method ensures that the entire process doesn't halt if one or more jobs fail.
Key Decisions
- Background Jobs: Using background jobs allows the synchronization to occur without blocking the user interface.
-
Bus::batch: This provides a convenient way to manage and monitor multiple jobs running in parallel. -
allowFailures(): This ensures that individual job failures don't prevent the entire synchronization process from completing.
Results
- Automated and comprehensive synchronization of all owned repositories.
- Elimination of manual data fetching, saving developer time.
- More complete and accurate data for analysis and reporting.
Lessons Learned
Implementing this feature highlighted the importance of robust error handling and efficient job management when dealing with large-scale data synchronization tasks. Using Bus::batch simplified the process and provided the necessary tools to handle potential failures gracefully.
Top comments (0)