-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from leepeuker/improve-job-processing
Update job processing and add job queue page
- Loading branch information
Showing
17 changed files
with
483 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php declare(strict_types=1); | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
final class UpdateJobQueueTable extends AbstractMigration | ||
{ | ||
public function down() : void | ||
{ | ||
$this->execute( | ||
<<<SQL | ||
DROP TABLE `job_queue` | ||
SQL | ||
); | ||
|
||
$this->execute( | ||
<<<SQL | ||
CREATE TABLE `job_queue` ( | ||
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, | ||
`job` TEXT NOT NULL, | ||
`created_at` DATETIME NOT NULL DEFAULT NOW(), | ||
PRIMARY KEY (`id`) | ||
) COLLATE="utf8mb4_unicode_ci" ENGINE=InnoDB | ||
SQL | ||
); | ||
} | ||
|
||
public function up() : void | ||
{ | ||
$this->execute( | ||
<<<SQL | ||
DROP TABLE `job_queue` | ||
SQL | ||
); | ||
|
||
$this->execute( | ||
<<<SQL | ||
CREATE TABLE `job_queue` ( | ||
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, | ||
`job_type` TEXT NOT NULL, | ||
`job_status` TEXT NOT NULL, | ||
`user_id` INT(10) UNSIGNED DEFAULT NULL, | ||
`parameters` TEXT DEFAULT NULL, | ||
`updated_at` DATETIME DEFAULT NULL ON UPDATE NOW(), | ||
`created_at` DATETIME NOT NULL DEFAULT NOW(), | ||
PRIMARY KEY (`id`), | ||
FOREIGN KEY (`user_id`) REFERENCES user (`id`) | ||
) COLLATE="utf8mb4_unicode_ci" ENGINE=InnoDB | ||
SQL | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Movary\ValueObject; | ||
|
||
use Movary\Util\Json; | ||
|
||
class Job | ||
{ | ||
private function __construct( | ||
private readonly int $id, | ||
private readonly JobType $type, | ||
private readonly JobStatus $status, | ||
private readonly ?int $userId, | ||
private readonly array $parameters, | ||
private readonly ?DateTime $updatedAt, | ||
private readonly DateTime $createdAt, | ||
) { | ||
} | ||
|
||
public static function createFromArray(array $data) : self | ||
{ | ||
return new self( | ||
$data['id'], | ||
JobType::createFromString($data['job_type']), | ||
JobStatus::createFromString($data['job_status']), | ||
$data['user_id'], | ||
$data['parameters'] === null ? [] : Json::decode($data['parameters']), | ||
$data['updated_at'] === null ? null : DateTime::createFromString($data['updated_at']), | ||
DateTime::createFromString($data['created_at']), | ||
); | ||
} | ||
|
||
public function getCreatedAt() : DateTime | ||
{ | ||
return $this->createdAt; | ||
} | ||
|
||
public function getId() : int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getParameters() : array | ||
{ | ||
return $this->parameters; | ||
} | ||
|
||
public function getStatus() : JobStatus | ||
{ | ||
return $this->status; | ||
} | ||
|
||
public function getType() : JobType | ||
{ | ||
return $this->type; | ||
} | ||
|
||
public function getUpdatedAt() : ?DateTime | ||
{ | ||
return $this->updatedAt; | ||
} | ||
|
||
public function getUserId() : ?int | ||
{ | ||
return $this->userId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Movary\ValueObject; | ||
|
||
use Movary\AbstractList; | ||
|
||
/** | ||
* @method Job[] getIterator() | ||
* @psalm-suppress ImplementedReturnTypeMismatch | ||
*/ | ||
class JobList extends AbstractList | ||
{ | ||
public static function create() : self | ||
{ | ||
return new self(); | ||
} | ||
|
||
public static function createFromArray(array $data) : self | ||
{ | ||
$list = new self(); | ||
|
||
foreach ($data as $movie) { | ||
$list->add(Job::createFromArray($movie)); | ||
} | ||
|
||
return $list; | ||
} | ||
|
||
private function add(Job $dto) : void | ||
{ | ||
$this->data[] = $dto; | ||
} | ||
} |
Oops, something went wrong.