Skip to content

Commit 193c8ce

Browse files
committed
feat: #14 allow to configure services
1 parent 44033e0 commit 193c8ce

File tree

100 files changed

+2536
-360
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+2536
-360
lines changed

api-nodes/Http/Controllers/NextTaskController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace ApiNodes\Http\Controllers;
44

55
use App\Models\Node;
6-
use App\Models\NodeTask\TaskStatus;
6+
use App\Models\NodeTasks\TaskStatus;
77
use App\Models\NodeTaskGroup;
88
use Illuminate\Database\Eloquent\Builder;
99
use Illuminate\Http\Response;

api-nodes/Http/Controllers/TaskController.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
namespace ApiNodes\Http\Controllers;
44

5-
use App\Casts\TaskResultCast;
65
use App\Models\NodeTask;
7-
use App\Models\NodeTask\ErrorResult;
6+
use App\Models\NodeTasks\ErrorResult;
87
use Illuminate\Http\Request;
98
use Illuminate\Http\Response;
109

@@ -20,7 +19,9 @@ public function complete(NodeTask $task, Request $request)
2019
return new Response(['error' => "Task didn't start yet."], 409);
2120
}
2221

23-
$result = TaskResultCast::RESULT_BY_TYPE[$task->type]::validateAndCreate($request->all());
22+
$resultClass = $task->type->result();
23+
24+
$result = $resultClass::validateAndCreate($request->all());
2425

2526
$task->complete($result);
2627

api-nodes/Http/Middleware/AgentTokenAuth.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace ApiNodes\Http\Middleware;
44

55
use App\Models\Node;
6-
use App\Models\NodeTask;
6+
use App\Models\NodeTasks;
77
use App\Models\Scopes\TeamScope;
88
use App\Models\Team;
99
use Closure;

app/Casts/TaskMetaCast.php

-56
This file was deleted.

app/Casts/TaskPayloadCast.php

-59
This file was deleted.

app/Casts/TaskResultCast.php

-63
This file was deleted.

app/Console/Commands/MakeNodeTask.php

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Support\Str;
7+
8+
class MakeNodeTask extends Command
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'make:node-task [taskName]';
16+
17+
/**
18+
* The console command description.
19+
*34
20+
* @var string
21+
*/
22+
protected $description = 'Create a new node task';
23+
24+
/**
25+
* Execute the console command.
26+
*/
27+
public function handle(): void
28+
{
29+
$this->promptForMissingArguments($this->input, $this->output);
30+
31+
$taskName = $this->hasArgument('taskName')
32+
? $this->argument('taskName')
33+
: $this->ask('Enter task name');
34+
35+
$taskName = Str::camel($taskName);
36+
$taskName = Str::ucfirst($taskName);
37+
38+
$this->info("Normalized Task Name: {$taskName}");
39+
40+
$taskDataFiles = [
41+
"Models/NodeTasks/{$taskName}/{$taskName}Meta.php" => $this->readStub('NodeTaskMeta', $taskName),
42+
"Models/NodeTasks/{$taskName}/{$taskName}Result.php" => $this->readStub('NodeTaskResult', $taskName),
43+
"Events/NodeTasks/{$taskName}/{$taskName}Completed.php" => $this->readStub('NodeTaskCompleted', $taskName),
44+
"Events/NodeTasks/{$taskName}/{$taskName}Failed.php" => $this->readStub('NodeTaskFailed', $taskName),
45+
];
46+
47+
$dirs = [
48+
"Events/NodeTasks/{$taskName}",
49+
"Models/NodeTasks/{$taskName}",
50+
];
51+
52+
foreach ($dirs as $dir) {
53+
$path = app_path($dir);
54+
55+
$this->info('Creating directory ' . $dir);
56+
57+
mkdir($path);
58+
}
59+
60+
foreach ($taskDataFiles as $abstractPath => $template) {
61+
$path = app_path($abstractPath);
62+
63+
$this->info('Writing ' . $abstractPath);
64+
65+
file_put_contents($path, $template);
66+
}
67+
68+
$this->info('Done!');
69+
}
70+
71+
protected function readStub($type, $taskName): string
72+
{
73+
$template = file_get_contents(__DIR__ . "/stubs/MakeNodeTask/$type.stub");
74+
75+
return str_replace('$taskName', $taskName, $template);
76+
}
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace App\Events\NodeTasks\$taskName;
4+
5+
use App\Events\NodeTasks\BaseTaskEvent;
6+
7+
class $taskNameCompleted extends BaseTaskEvent
8+
{
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace App\Events\NodeTasks\$taskName;
4+
5+
use App\Events\NodeTasks\BaseTaskEvent;
6+
7+
class $taskNameFailed extends BaseTaskEvent
8+
{
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Models\NodeTasks\$taskName;
4+
5+
use App\Models\NodeTasks\AbstractTaskMeta;
6+
7+
class $taskNameMeta extends AbstractTaskMeta
8+
{
9+
public function __construct(
10+
)
11+
{
12+
//
13+
}
14+
15+
public function formattedHtml(): string
16+
{
17+
return "$taskName - Task Payload";
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Models\NodeTasks\$taskName;
4+
5+
use App\Models\NodeTasks\AbstractTaskResult;
6+
7+
class $taskNameResult extends AbstractTaskResult
8+
{
9+
public function __construct(
10+
)
11+
{
12+
//
13+
}
14+
15+
public function formattedHtml(): string
16+
{
17+
return "$taskName - Task Result";
18+
}
19+
}

app/Events/Tasks/BaseTaskEvent.php renamed to app/Events/NodeTasks/BaseTaskEvent.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace App\Events\Tasks;
3+
namespace App\Events\NodeTasks;
44

55
use App\Models\NodeTask;
66
use Illuminate\Broadcasting\InteractsWithSockets;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App\Events\NodeTasks\CreateConfig;
4+
5+
use App\Events\NodeTasks\BaseTaskEvent;
6+
7+
class CreateConfigCompleted extends BaseTaskEvent
8+
{
9+
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App\Events\NodeTasks\CreateConfig;
4+
5+
use App\Events\NodeTasks\BaseTaskEvent;
6+
7+
class CreateConfigFailed extends BaseTaskEvent
8+
{
9+
10+
}

0 commit comments

Comments
 (0)