1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace Resta\Console\Source\Worker;
|
4
|
|
|
|
5
|
|
|
use Resta\Worker\WorkerManager;
|
6
|
|
|
use Resta\Console\ConsoleOutputter;
|
7
|
|
|
use Resta\Console\ConsoleListAccessor;
|
8
|
|
|
|
9
|
|
|
class Worker extends ConsoleOutputter {
|
10
|
|
|
|
11
|
|
|
use ConsoleListAccessor;
|
12
|
|
|
|
13
|
|
|
/**
|
14
|
|
|
* @var $type
|
|
|
|
|
15
|
|
|
*/
|
16
|
|
|
public $type = 'worker';
|
17
|
|
|
|
18
|
|
|
/**
|
19
|
|
|
* @var $define
|
|
|
|
|
20
|
|
|
*/
|
21
|
|
|
public $define = 'begins worker for application';
|
22
|
|
|
|
23
|
|
|
/**
|
24
|
|
|
* @var $commandRule
|
|
|
|
|
25
|
|
|
*/
|
26
|
|
|
public $commandRule = ['worker'];
|
27
|
|
|
|
28
|
|
|
/**
|
29
|
|
|
* @inheritDoc
|
30
|
|
|
*/
|
31
|
|
|
public function run()
|
32
|
|
|
{
|
33
|
|
|
$workerName = $this->projectName().'-'.$this->argument['worker'];
|
34
|
|
|
app()->register('WORKER',$workerName);
|
35
|
|
|
app()->register('PROJECT_NAME',strtolower($this->projectName()));
|
36
|
|
|
app()->register('WORKER_STATUS',false);
|
37
|
|
|
|
38
|
|
|
app()->resolve(WorkerManager::class,['args'=>$this->argument])->execute();
|
39
|
|
|
}
|
40
|
|
|
|
41
|
|
|
/**
|
42
|
|
|
* @inheritDoc
|
43
|
|
|
*/
|
44
|
|
|
public function stop()
|
45
|
|
|
{
|
46
|
|
|
$workerName = $this->projectName().'-'.$this->argument['worker'];
|
47
|
|
|
app()->register('WORKER',$workerName);
|
48
|
|
|
app()->register('PROJECT_NAME',strtolower($this->projectName()));
|
49
|
|
|
app()->register('WORKER_STATUS',true);
|
50
|
|
|
|
51
|
|
|
app()->resolve(WorkerManager::class,['args'=>$this->argument])->execute();
|
52
|
|
|
}
|
53
|
|
|
|
54
|
|
|
/**
|
55
|
|
|
* @inheritDoc
|
56
|
|
|
*/
|
57
|
|
|
public function create()
|
58
|
|
|
{
|
59
|
|
|
if(!file_exists(app()->path()->workers())){
|
60
|
|
|
$this->directory['worker'] = app()->path()->workers();
|
61
|
|
|
$this->file->makeDirectory($this);
|
62
|
|
|
}
|
63
|
|
|
|
64
|
|
|
$this->argument['workerNamespace'] = app()->namespace()->workers();
|
65
|
|
|
$this->argument['workerClass'] = ucfirst($this->argument['worker']).'';
|
66
|
|
|
$this->argument['projectName'] = strtolower($this->projectName());
|
67
|
|
|
|
68
|
|
|
$this->touch['worker/worker']= app()->path()->workers().'/'.$this->argument['worker'].'.php';
|
69
|
|
|
|
70
|
|
|
|
71
|
|
|
$this->file->touch($this);
|
72
|
|
|
|
73
|
|
|
echo $this->classical(' > Worker file called as "'.$this->argument['worker'].'" has been successfully created in the '.app()->path()->workers().'');
|
74
|
|
|
}
|
75
|
|
|
|
76
|
|
|
|
77
|
|
|
} |