Skip to content

Commit 074528d

Browse files
authored
Adding TaskScheduler (#125)
1 parent 3ac365b commit 074528d

File tree

6 files changed

+75
-31
lines changed

6 files changed

+75
-31
lines changed

config/packages/github_api.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,45 @@ services:
3333
class: Symfony\Component\HttpClient\Retry\GenericRetryStrategy
3434
arguments:
3535
- [0, 404, 423, 425, 429, 500, 502, 503, 504, 507, 510]
36+
37+
38+
# Register different APIs as services
39+
40+
Github\Api\Issue:
41+
factory: ['@Github\Client', api]
42+
arguments: [issue]
43+
44+
Github\Api\Issue\Comments:
45+
factory: ['@Github\Api\Issue', comments]
46+
calls:
47+
- ['setPerPage', [100]]
48+
49+
Github\Api\Issue\Labels:
50+
factory: ['@Github\Api\Issue', labels]
51+
calls:
52+
- ['setPerPage', [100]]
53+
54+
Github\Api\Issue\Milestones:
55+
factory: ['@Github\Api\Issue', milestones]
56+
57+
Github\Api\Issue\Timeline:
58+
factory: ['@Github\Api\Issue', timeline]
59+
calls:
60+
- [configure]
61+
62+
Github\Api\PullRequest:
63+
factory: ['@Github\Client', api]
64+
arguments: [pullRequest]
65+
66+
Github\Api\PullRequest\Review:
67+
factory: ['@Github\Api\PullRequest', reviews]
68+
69+
Github\Api\Repo:
70+
factory: ['@Github\Client', api]
71+
arguments: [repo]
72+
73+
Github\Api\Search:
74+
factory: ['@Github\Client', api]
75+
arguments: [search]
76+
calls:
77+
- ['setPerPage', [100]]

config/services.yaml

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -61,32 +61,6 @@ services:
6161
resource: '../src/Subscriber/*'
6262
autoconfigure: false
6363

64-
Github\Api\Issue:
65-
factory: ['@Github\Client', api]
66-
arguments: [issue]
67-
68-
Github\Api\PullRequest:
69-
factory: ['@Github\Client', api]
70-
arguments: [pullRequest]
71-
72-
Github\Api\Repo:
73-
factory: ['@Github\Client', api]
74-
arguments: [repo]
75-
76-
Github\Api\Search:
77-
factory: ['@Github\Client', api]
78-
arguments: [search]
79-
80-
Github\Api\Issue\Labels:
81-
factory: ['@Github\Api\Issue', labels]
82-
calls:
83-
- ['setPerPage', [100]]
84-
85-
Github\Api\Issue\Milestones:
86-
factory: ['@Github\Api\Issue', milestones]
87-
88-
Github\Api\Issue\Comments:
89-
factory: ['@Github\Api\Issue', comments]
9064

9165
App\Api\Issue\IssueApi: '@App\Api\Issue\GithubIssueApi'
9266
App\Api\Label\LabelApi: '@App\Api\Label\GithubLabelApi'

config/services_test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ services:
66
App\Api\Issue\IssueApi: '@App\Api\Issue\NullIssueApi'
77
App\Api\Label\LabelApi: '@App\Api\Label\StaticLabelApi'
88
App\Api\Milestone\MilestoneApi: '@App\Api\Milestone\StaticMilestoneApi'
9-
App\Api\PullRequest\PullRequestApi: '@App\Api\PullRequest\GithubPullRequestApi'
9+
App\Api\PullRequest\PullRequestApi: '@App\Api\PullRequest\NullPullRequestApi'
1010
App\Api\Status\StatusApi: '@App\Api\Status\NullStatusApi'

src/Api/PullRequest/GithubPullRequestApi.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
*/
1313
class GithubPullRequestApi implements PullRequestApi
1414
{
15-
/**
16-
* @var Repo
17-
*/
1815
private $github;
1916
private $pullRequest;
2017
private $search;

src/Command/RunTaskCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
4040
try {
4141
$this->taskRunner->run($task);
4242
} catch (\Exception $e) {
43-
$this->logger->error('Failed running task', ['excpetion' => $e]);
43+
$this->logger->error('Failed running task', ['exception' => $e]);
4444
$output->writeln($e->getMessage());
4545
}
4646
}

src/Service/TaskScheduler.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Service;
6+
7+
use App\Entity\Task;
8+
use App\Model\Repository;
9+
use App\Repository\TaskRepository;
10+
11+
/**
12+
* Schedule a job to run later.
13+
*
14+
* @author Tobias Nyholm <[email protected]>
15+
*/
16+
class TaskScheduler
17+
{
18+
private $taskRepo;
19+
20+
public function __construct(TaskRepository $taskRepo)
21+
{
22+
$this->taskRepo = $taskRepo;
23+
}
24+
25+
public function runLater(Repository $repository, $number, int $action, \DateTimeImmutable $checkAt)
26+
{
27+
$task = new Task($repository->getFullName(), $number, $action, $checkAt);
28+
$this->taskRepo->persist($task);
29+
$this->taskRepo->flush();
30+
}
31+
}

0 commit comments

Comments
 (0)