Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

refactor: streamline job status retrieval and clean up repository interface

Andras Bacsai7582d7dd8b6a
diff --git a/app/Console/Commands/HorizonManage.php b/app/Console/Commands/HorizonManage.php
index 9acc16ed60..ca2da147c4 100644
--- a/app/Console/Commands/HorizonManage.php
+++ b/app/Console/Commands/HorizonManage.php
@@ -173,11 +173,6 @@ class HorizonManage extends Command
public function getJobStatus(string $jobId)
{
- $jobFound = app(JobRepository::class)->getJobs([$jobId]);
- if ($jobFound->isEmpty()) {
- return 'unknown';
- }
-
- return $jobFound->first()->status;
+ return getJobStatus($jobId);
}
}
diff --git a/app/Contracts/CustomJobRepositoryInterface.php b/app/Contracts/CustomJobRepositoryInterface.php
index 689b1897fb..1fbd71f464 100644
--- a/app/Contracts/CustomJobRepositoryInterface.php
+++ b/app/Contracts/CustomJobRepositoryInterface.php
@@ -16,9 +16,4 @@ interface CustomJobRepositoryInterface extends JobRepository
* Get the count of jobs with a specific status.
*/
public function countJobsByStatus(string $status): int;
-
- /**
- * Get jobs that have been running longer than a specified duration in seconds.
- */
- public function getLongRunningJobs(int $seconds): Collection;
}
diff --git a/app/Models/ApplicationDeploymentQueue.php b/app/Models/ApplicationDeploymentQueue.php
index f6a88a692a..95c78d725e 100644
--- a/app/Models/ApplicationDeploymentQueue.php
+++ b/app/Models/ApplicationDeploymentQueue.php
@@ -72,10 +72,6 @@ class ApplicationDeploymentQueue extends Model
public function getHorizonJobStatus()
{
- if (! $this->horizon_job_id) {
- return 'unknown';
- }
-
return getJobStatus($this->horizon_job_id);
}
diff --git a/app/Repositories/CustomJobRepository.php b/app/Repositories/CustomJobRepository.php
index af299895de..502dd252b7 100644
--- a/app/Repositories/CustomJobRepository.php
+++ b/app/Repositories/CustomJobRepository.php
@@ -21,25 +21,12 @@ class CustomJobRepository extends RedisJobRepository implements CustomJobReposit
return $this->getJobsByStatus('reserved');
}
- public function getJobStatus(string $jobId): string
- {
- return $this->connection()->get('job:'.$jobId.':status');
- }
-
- /**
- * Get all jobs with a specific status.
- */
- public function getJobsByStatus(string $status, ?string $worker = null): Collection
+ public function getJobsByStatus(string $status): Collection
{
$jobs = new Collection;
- $this->getRecent()->each(function ($job) use ($jobs, $status, $worker) {
+ $this->getRecent()->each(function ($job) use ($jobs, $status) {
if ($job->status === $status) {
- if ($worker) {
- if ($job->worker !== $worker) {
- return;
- }
- }
$jobs->push($job);
}
});
@@ -47,32 +34,11 @@ class CustomJobRepository extends RedisJobRepository implements CustomJobReposit
return $jobs;
}
- /**
- * Get the count of jobs with a specific status.
- */
public function countJobsByStatus(string $status): int
{
return $this->getJobsByStatus($status)->count();
}
- /**
- * Get jobs that have been running longer than a specified duration in seconds.
- */
- public function getLongRunningJobs(int $seconds): Collection
- {
- $jobs = new Collection;
-
- $this->getRecent()->each(function ($job) use ($jobs, $seconds) {
- if ($job->status === 'reserved' &&
- isset($job->reserved_at) &&
- (time() - strtotime($job->reserved_at)) > $seconds) {
- $jobs->push($job);
- }
- });
-
- return $jobs;
- }
-
public function getQueues(): array
{
$queues = $this->connection()->keys('queue:*');
diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php
index 17e17b7fa9..fd7e63b75f 100644
--- a/bootstrap/helpers/shared.php
+++ b/bootstrap/helpers/shared.php
@@ -1262,8 +1262,8 @@ function isAnyDeploymentInprogress()
$runningJobs = ApplicationDeploymentQueue::where('horizon_job_worker', gethostname())->where('status', ApplicationDeploymentStatus::IN_PROGRESS->value)->get();
$horizonJobIds = [];
foreach ($runningJobs as $runningJob) {
- $horizonJobId = getJobStatus($runningJob->horizon_job_id);
- if ($horizonJobId === 'unknown') {
+ $horizonJobStatus = getJobStatus($runningJob->horizon_job_id);
+ if ($horizonJobStatus === 'unknown') {
return true;
}
$horizonJobIds[] = $runningJob->horizon_job_id;
@@ -4080,8 +4080,11 @@ function convertGitUrl(string $gitRepository, string $deploymentType, ?GithubApp
];
}
-function getJobStatus(string $jobId)
+function getJobStatus(?string $jobId = null)
{
+ if (blank($jobId)) {
+ return 'unknown';
+ }
$jobFound = app(JobRepository::class)->getJobs([$jobId]);
if ($jobFound->isEmpty()) {
return 'unknown';