1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: arthur |
5
|
|
|
* Date: 28.10.18 |
6
|
|
|
* Time: 17:25. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Modules\Demo\Jobs; |
10
|
|
|
|
11
|
|
|
use Foundation\Abstracts\Jobs\Job; |
12
|
|
|
use Modules\Account\Contracts\AccountServiceContract; |
13
|
|
|
use Modules\Account\Services\AccountService; |
14
|
|
|
use Modules\Auth0\Contracts\Auth0ServiceContract; |
15
|
|
|
use Modules\Auth0\Services\Auth0Service; |
16
|
|
|
use Modules\Auth0\Traits\Auth0TestUser; |
17
|
|
|
use Modules\Machine\Contracts\MachineServiceContract; |
18
|
|
|
use Modules\Machine\Services\MachineService; |
19
|
|
|
|
20
|
|
|
class AlterDemoDataJob extends Job |
21
|
|
|
{ |
22
|
|
|
use Auth0TestUser; |
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var MachineService |
26
|
|
|
*/ |
27
|
|
|
protected $machineService; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var AccountService |
31
|
|
|
*/ |
32
|
|
|
protected $accountService; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var Auth0Service |
36
|
|
|
*/ |
37
|
|
|
protected $userService; |
38
|
|
|
|
39
|
90 |
|
public function __construct() |
40
|
|
|
{ |
41
|
90 |
|
$this->machineService = app()->make(MachineServiceContract::class); |
42
|
90 |
|
$this->accountService = app()->make(AccountServiceContract::class); |
43
|
90 |
|
$this->userService = app()->make(Auth0ServiceContract::class); |
44
|
90 |
|
} |
45
|
|
|
|
46
|
|
|
public function handle() |
47
|
|
|
{ |
48
|
|
|
$this->alterMachineData(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
protected function alterMachineData() |
52
|
|
|
{ |
53
|
|
|
foreach ($this->machineService->getByUserId($this->getTestUser()->id) as $machine) { |
54
|
|
|
$this->machineService->heartbeat($machine, [ |
55
|
|
|
'cpu_usage' => rand(0, 100), |
56
|
|
|
'memory_usage' => rand(1, $machine->memory_available), |
57
|
|
|
]); |
58
|
|
|
$this->machineService->update($machine, ['online' => (bool) rand(0, 1)]); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
protected function alterAccountData() |
63
|
|
|
{ |
64
|
|
|
foreach ($this->accountService->getByUserId($this->getTestUser()->id) as $account) { |
65
|
|
|
$this->accountService->heartbeat($account, [ |
66
|
|
|
'cpu_usage' => rand(0, 100), |
67
|
|
|
'memory_usage' => rand(1, $account->memory_available), |
68
|
|
|
]); |
69
|
|
|
$this->accountService->update($account, ['online' => (bool) rand(0, 1)]); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|