Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
marco76tv committed Feb 29, 2024
1 parent 2fde98c commit a2b09c0
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 63 deletions.
19 changes: 13 additions & 6 deletions Models/FailedJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,29 @@
use Illuminate\Database\Eloquent\Builder;

/**
* Modules\Job\Models\FailedJob
* Modules\Job\Models\FailedJob.
*
* @method static \Modules\Job\Database\Factories\FailedJobFactory factory($count = null, $state = [])
* @method static Builder|FailedJob newModelQuery()
* @method static Builder|FailedJob newQuery()
* @method static Builder|FailedJob query()
* @property int $id
* @method static Builder|FailedJob newModelQuery()
* @method static Builder|FailedJob newQuery()
* @method static Builder|FailedJob query()
*
* @property int $id
* @property string $uuid
* @property string $connection
* @property string $queue
* @property array $payload
* @property array $payload
* @property string $exception
* @property string $failed_at
*
* @method static Builder|FailedJob whereConnection($value)
* @method static Builder|FailedJob whereException($value)
* @method static Builder|FailedJob whereFailedAt($value)
* @method static Builder|FailedJob whereId($value)
* @method static Builder|FailedJob wherePayload($value)
* @method static Builder|FailedJob whereQueue($value)
* @method static Builder|FailedJob whereUuid($value)
*
* @mixin \Eloquent
*/
class FailedJob extends BaseModel
Expand All @@ -46,6 +49,10 @@ class FailedJob extends BaseModel
];

protected $casts = [
'updated_by' => 'string',
'created_by' => 'string',
'deleted_by' => 'string',

'payload' => 'array',
];
}
12 changes: 11 additions & 1 deletion Models/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Support\Carbon;

use function Safe\json_decode;

use Webmozart\Assert\Assert;

/**
Expand All @@ -27,6 +29,7 @@
* @property string|null $created_by
* @property string|null $updated_by
* @property Carbon|null $updated_at
*
* @method static \Modules\Job\Database\Factories\JobFactory factory($count = null, $state = [])
* @method static Builder|Job newModelQuery()
* @method static Builder|Job newQuery()
Expand All @@ -41,8 +44,10 @@
* @method static Builder|Job whereReservedAt($value)
* @method static Builder|Job whereUpdatedAt($value)
* @method static Builder|Job whereUpdatedBy($value)
*
* @property mixed $display_name
* @property-read mixed $status
* @property mixed $status
*
* @mixin \Eloquent
*/
class Job extends BaseModel
Expand All @@ -58,6 +63,10 @@ class Job extends BaseModel
];

protected $casts = [
'updated_by' => 'string',
'created_by' => 'string',
'deleted_by' => 'string',

'payload' => 'array',
'created_at' => 'datetime',
'updated_at' => 'datetime',
Expand All @@ -80,6 +89,7 @@ public function status(): Attribute
if ($this->reserved_at) {
return 'running';
}

return 'waiting';
},
);
Expand Down
64 changes: 35 additions & 29 deletions Models/JobBatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,34 @@
use Illuminate\Support\Collection;

/**
* Modules\Job\Models\JobBatch
* Modules\Job\Models\JobBatch.
*
* @property string $id
* @property string $name
* @property int $total_jobs
* @property int $pending_jobs
* @property int $failed_jobs
* @property string $failed_job_ids
* @property string $id
* @property string $name
* @property int $total_jobs
* @property int $pending_jobs
* @property int $failed_jobs
* @property string $failed_job_ids
* @property Collection|null $options
* @property Carbon|null $cancelled_at
* @property Carbon $created_at
* @property Carbon|null $finished_at
* @property Carbon|null $cancelled_at
* @property Carbon $created_at
* @property Carbon|null $finished_at
*
* @method static \Modules\Job\Database\Factories\JobBatchFactory factory($count = null, $state = [])
* @method static Builder|JobBatch newModelQuery()
* @method static Builder|JobBatch newQuery()
* @method static Builder|JobBatch query()
* @method static Builder|JobBatch whereCancelledAt($value)
* @method static Builder|JobBatch whereCreatedAt($value)
* @method static Builder|JobBatch whereFailedJobIds($value)
* @method static Builder|JobBatch whereFailedJobs($value)
* @method static Builder|JobBatch whereFinishedAt($value)
* @method static Builder|JobBatch whereId($value)
* @method static Builder|JobBatch whereName($value)
* @method static Builder|JobBatch whereOptions($value)
* @method static Builder|JobBatch wherePendingJobs($value)
* @method static Builder|JobBatch whereTotalJobs($value)
* @method static Builder|JobBatch newModelQuery()
* @method static Builder|JobBatch newQuery()
* @method static Builder|JobBatch query()
* @method static Builder|JobBatch whereCancelledAt($value)
* @method static Builder|JobBatch whereCreatedAt($value)
* @method static Builder|JobBatch whereFailedJobIds($value)
* @method static Builder|JobBatch whereFailedJobs($value)
* @method static Builder|JobBatch whereFinishedAt($value)
* @method static Builder|JobBatch whereId($value)
* @method static Builder|JobBatch whereName($value)
* @method static Builder|JobBatch whereOptions($value)
* @method static Builder|JobBatch wherePendingJobs($value)
* @method static Builder|JobBatch whereTotalJobs($value)
*
* @mixin \Eloquent
*/
class JobBatch extends BaseModel
Expand All @@ -49,17 +51,17 @@ class JobBatch extends BaseModel
* Indicates if the IDs are auto-incrementing.
*/
/**
* @var bool
*/
public $incrementing = false;
* @var bool
*/
public $incrementing = false;

/**
* The "type" of the primary key ID.
*/
/**
* @var string
*/
protected $keyType = 'string';
* @var string
*/
protected $keyType = 'string';

protected $fillable = [
'id',
Expand All @@ -82,6 +84,10 @@ class JobBatch extends BaseModel
* @var array<string, string>
*/
protected $casts = [
'updated_by' => 'string',
'created_by' => 'string',
'deleted_by' => 'string',

'options' => 'collection',
'failed_jobs' => 'integer',
'created_at' => 'datetime',
Expand Down
11 changes: 9 additions & 2 deletions Models/JobManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
* @property Carbon|null $cancelled_at
* @property Carbon $created_at
* @property Carbon|null $finished_at
*
* @method static \Modules\Job\Database\Factories\JobManagerFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder|JobManager newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|JobManager newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|JobManager query()
* @property-read mixed $status
*
* @property mixed $status
*
* @mixin \Eloquent
*/
class JobManager extends BaseModel
Expand All @@ -48,6 +51,10 @@ class JobManager extends BaseModel
];

protected $casts = [
'updated_by' => 'string',
'created_by' => 'string',
'deleted_by' => 'string',

'failed' => 'bool',
'started_at' => 'datetime',
'finished_at' => 'datetime',
Expand Down Expand Up @@ -81,7 +88,7 @@ public function isFinished(): bool
return true;
}

return $this->finished_at !== null;
return null !== $this->finished_at;
}

public function hasFailed(): bool
Expand Down
6 changes: 6 additions & 0 deletions Models/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property \Modules\Job\Models\Task|null $task
*
* @method static \Illuminate\Database\Eloquent\Builder|Result newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Result newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Result query()
Expand All @@ -35,6 +36,7 @@
* @method static \Illuminate\Database\Eloquent\Builder|Result whereTaskId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Result whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Result whereUpdatedBy($value)
*
* @mixin \Eloquent
*/
class Result extends BaseModel
Expand All @@ -49,6 +51,10 @@ class Result extends BaseModel
];

protected $casts = [
'updated_by' => 'string',
'created_by' => 'string',
'deleted_by' => 'string',

'ran_at' => 'datetime',
];

Expand Down
44 changes: 26 additions & 18 deletions Models/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,23 @@
use Modules\Job\Enums\Status;

/**
* Modules\Job\Models\Result
* Modules\Job\Models\Result.
*
* @property Status $status
* @property array $options
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Modules\Job\Models\ScheduleHistory> $histories
* @property-read int|null $histories_count
* @method static Builder|Schedule active()
* @property Status $status
* @property array $options
* @property \Illuminate\Database\Eloquent\Collection<int, \Modules\Job\Models\ScheduleHistory> $histories
* @property int|null $histories_count
*
* @method static Builder|Schedule active()
* @method static \Modules\Job\Database\Factories\ScheduleFactory factory($count = null, $state = [])
* @method static Builder|Schedule inactive()
* @method static Builder|Schedule newModelQuery()
* @method static Builder|Schedule newQuery()
* @method static Builder|Schedule onlyTrashed()
* @method static Builder|Schedule query()
* @method static Builder|Schedule withTrashed()
* @method static Builder|Schedule withoutTrashed()
* @method static Builder|Schedule inactive()
* @method static Builder|Schedule newModelQuery()
* @method static Builder|Schedule newQuery()
* @method static Builder|Schedule onlyTrashed()
* @method static Builder|Schedule query()
* @method static Builder|Schedule withTrashed()
* @method static Builder|Schedule withoutTrashed()
*
* @mixin \Eloquent
*/
class Schedule extends BaseModel
Expand All @@ -38,7 +40,7 @@ class Schedule extends BaseModel
*
* @var string
*/
//protected $table;
// protected $table;

protected $fillable = [
'command',
Expand Down Expand Up @@ -69,6 +71,10 @@ class Schedule extends BaseModel
'options_with_value' => '{}',
];
protected $casts = [
'updated_by' => 'string',
'created_by' => 'string',
'deleted_by' => 'string',

'params' => 'array',
'options' => 'array',
'options_with_value' => 'array',
Expand Down Expand Up @@ -111,8 +117,8 @@ public function getArguments(): array
if (empty($value['value'])) {
continue;
}
if (isset($value['type']) && $value['type'] === 'function') {
eval('$arguments[$argument] = (string) ' . $value['value']);
if (isset($value['type']) && 'function' === $value['type']) {
eval('$arguments[$argument] = (string) '.$value['value']);
} else {
$arguments[$value['name'] ?? $argument] = $value['value'];
}
Expand All @@ -128,10 +134,12 @@ public function getOptions(): array
if (! empty($options_with_value)) {
$options = $options->merge($options_with_value);
}

return $options->map(static function ($value, $key) {
if (is_array($value)) {
return '--' . ($value['name'] ?? $key) . '=' . $value['value'];
return '--'.($value['name'] ?? $key).'='.$value['value'];
}

return "--{$value}";
})->toArray();
}
Expand All @@ -143,4 +151,4 @@ public static function getEnvironments(): Collection
->get('environments')
->pluck('environments', 'environments');
}
}
}
20 changes: 13 additions & 7 deletions Models/ScheduleHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
* Modules\Job\Models\ScheduleHistory
* Modules\Job\Models\ScheduleHistory.
*
* @property \Modules\Job\Models\Schedule|null $command
*
* @property-read \Modules\Job\Models\Schedule|null $command
* @method static \Modules\Job\Database\Factories\ScheduleHistoryFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder|ScheduleHistory newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ScheduleHistory newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ScheduleHistory query()
* @method static \Illuminate\Database\Eloquent\Builder|ScheduleHistory newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ScheduleHistory newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ScheduleHistory query()
*
* @mixin \Eloquent
*/
class ScheduleHistory extends BaseModel
Expand All @@ -27,7 +29,7 @@ class ScheduleHistory extends BaseModel
*
* @var string
*/
//protected $table;
// protected $table;

protected $fillable = [
'command',
Expand All @@ -36,6 +38,10 @@ class ScheduleHistory extends BaseModel
'options',
];
protected $casts = [
'updated_by' => 'string',
'created_by' => 'string',
'deleted_by' => 'string',

'params' => 'array',
'options' => 'array',
];
Expand All @@ -59,4 +65,4 @@ public function command(): BelongsTo
{
return $this->belongsTo(Schedule::class, 'schedule_id', 'id');
}
}
}

0 comments on commit a2b09c0

Please sign in to comment.