Passed
Push — master ( f51c1b...16736d )
by Arthur
05:36
created

AlterDemoDataJob::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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
12
use Foundation\Abstracts\Jobs\Job;
13
use Modules\Auth0\Contracts\Auth0ServiceContract;
14
use Modules\Machine\Contracts\MachineServiceContract;
15
use Modules\Machine\Services\MachineService;
16
use Modules\User\Entities\User;
17
18
class AlterDemoDataJob extends Job
19
{
20
21
    /**
22
     * @var MachineService
23
     */
24
    protected $machineService;
25
26
    /**
27
     * @var User
28
     */
29
    protected $user;
30
31
32
    public function handle()
33
    {
34
        $this->boot();
35
        $this->alterMachineData();
36
    }
37
38
    protected function boot()
39
    {
40
        $this->machineService = app()->make(MachineServiceContract::class);
41
        $this->user = app()->make(Auth0ServiceContract::class)->getTestUser();
42
    }
43
44
    protected function alterMachineData()
45
    {
46
        foreach ($this->machineService->allByUserId($this->user->id) as $machine) {
47
            $this->machineService->heartbeat($machine, [
48
                'cpu_usage' => rand(0, 100),
49
                'memory_usage' => rand(1, $machine->memory_available)
50
            ]);
51
        }
52
    }
53
}
54