File tree 7 files changed +38
-29
lines changed
7 files changed +38
-29
lines changed Original file line number Diff line number Diff line change @@ -13,19 +13,26 @@ public function index()
13
13
14
14
}
15
15
16
- public function simpleTask ()
16
+ public function randomResult ()
17
17
{
18
- sleep (3 );
19
- echo 'This is a simple task ' ;
20
- }
21
-
22
- public function dateCheck ($ date )
23
- {
24
- if (date ('Y-m-d ' ) == $ date )
25
- echo 'matched ' ;
26
- else
27
- echo 'not matches ' ;
28
- return true ;
18
+ $ rand = rand (0 , 4 );
19
+ echo 'The winner is number ' . $ rand . PHP_EOL ;
20
+ switch ($ rand ) {
21
+ case 0 :
22
+ die ('Bad result ' );
23
+ case 1 :
24
+ return true ;
25
+ case 2 :
26
+ return false ;
27
+ case 3 :
28
+ throw new Exception ('Unexpected situation ' );
29
+ case 4 :
30
+ $ micro_seconds = rand (1000000 , 4000000 );
31
+ echo 'Going to wait for some time ' . PHP_EOL ;
32
+ usleep ($ micro_seconds );
33
+ return true ;
34
+ }
35
+ return false ;
29
36
}
30
37
31
38
}
Original file line number Diff line number Diff line change 7
7
* Date: 20.12.15
8
8
* Time: 20:56
9
9
*/
10
- class CronController extends BaseController
10
+ class TasksController extends BaseController
11
11
{
12
12
public function index ()
13
13
{
@@ -66,7 +66,7 @@ public function runTask()
66
66
}
67
67
} elseif (isset ($ _POST ['custom_task ' ])) {
68
68
$ result = TaskManager::parseAndRunCommand ($ _POST ['custom_task ' ]);
69
- echo ($ result ) ? ' success ' : ' failed ' ;
69
+ echo ($ result ) ? 'success ' : 'failed ' ;
70
70
} else
71
71
echo 'empty task id ' ;
72
72
}
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ function __autoload($class_name)
8
8
}
9
9
10
10
spl_autoload_register ('__autoload ' );
11
- $ controller = 'Cron ' ;
11
+ $ controller = 'tasks ' ;
12
12
$ method = 'index ' ;
13
13
14
14
if (isset ($ argv ) && 2 < count ($ argv )) {
Original file line number Diff line number Diff line change 39
39
<input type="submit" value="Export" class="btn btn-primary">
40
40
</div>
41
41
</form>
42
- <div id="export_result">
43
- </div>
42
+ <code id="export_result"></code>
44
43
</div>
Original file line number Diff line number Diff line change @@ -41,11 +41,12 @@ class="show_output">Show output</a>
41
41
<div class="modal-dialog">
42
42
<div class="modal-content">
43
43
<div class="modal-header">
44
- <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
44
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
45
+ aria-hidden="true">×</span></button>
45
46
<h4 class="modal-title" id="myModalLabel">Task run output</h4>
46
47
</div>
47
- <div class="modal-body" id="output_container" >
48
- <p >Loading...</p >
48
+ <div class="modal-body">
49
+ <pre id="output_container" >Loading...</pre >
49
50
</div>
50
51
</div>
51
52
</div>
Original file line number Diff line number Diff line change 91
91
</form>
92
92
<div id="output_section" style="display: none;">
93
93
<h3>Task output</h3>
94
- <div class="alert alert-info" id="task_output_container">
95
- </div>
94
+ <pre id="task_output_container"></pre>
96
95
</div>
Original file line number Diff line number Diff line change @@ -112,20 +112,23 @@ public static function parseAndRunCommand($command)
112
112
113
113
$ result = call_user_func_array ([$ obj , $ method ], $ args );
114
114
} catch (\Exception $ e ) {
115
- echo ' Caught an exception: ' . get_class ($ e ) . ': ' . $ e ->getMessage () . PHP_EOL ;
115
+ echo 'Caught an exception: ' . get_class ($ e ) . ': ' . PHP_EOL . $ e ->getMessage () . PHP_EOL ;
116
116
return false ;
117
117
}
118
118
return $ result ;
119
119
}
120
120
121
121
protected static function parseCommand ($ command )
122
122
{
123
- preg_match ('/(\w+)::(\w+)\((.*)\)/ ' , $ command , $ match );
124
- return [
125
- $ match [1 ],
126
- $ match [2 ],
127
- explode (', ' , $ match [3 ])
128
- ];
123
+ if (preg_match ('/(\w+)::(\w+)\((.*)\)/ ' , $ command , $ match )) {
124
+ ;
125
+ return [
126
+ $ match [1 ],
127
+ $ match [2 ],
128
+ explode (', ' , $ match [3 ])
129
+ ];
130
+ } else
131
+ throw new CrontabManagerException ('Command not recognized ' );
129
132
}
130
133
131
134
public static function getControllerMethods ($ class )
You can’t perform that action at this time.
0 commit comments