Skip to content

Commit e2f62ae

Browse files
committed
fixes
1 parent fb489ab commit e2f62ae

File tree

7 files changed

+38
-29
lines changed

7 files changed

+38
-29
lines changed

examples/active_record/Controllers/ActiveController.php

+19-12
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,26 @@ public function index()
1313

1414
}
1515

16-
public function simpleTask()
16+
public function randomResult()
1717
{
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;
2936
}
3037

3138
}

examples/active_record/Controllers/CronController.php examples/active_record/Controllers/TasksController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Date: 20.12.15
88
* Time: 20:56
99
*/
10-
class CronController extends BaseController
10+
class TasksController extends BaseController
1111
{
1212
public function index()
1313
{
@@ -66,7 +66,7 @@ public function runTask()
6666
}
6767
} elseif (isset($_POST['custom_task'])) {
6868
$result = TaskManager::parseAndRunCommand($_POST['custom_task']);
69-
echo ($result) ? ' success' : ' failed';
69+
echo ($result) ? 'success' : 'failed';
7070
} else
7171
echo 'empty task id';
7272
}

examples/active_record/index.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function __autoload($class_name)
88
}
99

1010
spl_autoload_register('__autoload');
11-
$controller = 'Cron';
11+
$controller = 'tasks';
1212
$method = 'index';
1313

1414
if (isset($argv) && 2 < count($argv)) {

examples/active_record/views/export.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,5 @@
3939
<input type="submit" value="Export" class="btn btn-primary">
4040
</div>
4141
</form>
42-
<div id="export_result">
43-
</div>
42+
<code id="export_result"></code>
4443
</div>

examples/active_record/views/runs_list.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ class="show_output">Show output</a>
4141
<div class="modal-dialog">
4242
<div class="modal-content">
4343
<div class="modal-header">
44-
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
44+
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
45+
aria-hidden="true">&times;</span></button>
4546
<h4 class="modal-title" id="myModalLabel">Task run output</h4>
4647
</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>
4950
</div>
5051
</div>
5152
</div>

examples/active_record/views/tasks_list.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,5 @@
9191
</form>
9292
<div id="output_section" style="display: none;">
9393
<h3>Task output</h3>
94-
<div class="alert alert-info" id="task_output_container">
95-
</div>
94+
<pre id="task_output_container"></pre>
9695
</div>

src/TaskManager.php

+10-7
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,23 @@ public static function parseAndRunCommand($command)
112112

113113
$result = call_user_func_array([$obj, $method], $args);
114114
} 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;
116116
return false;
117117
}
118118
return $result;
119119
}
120120

121121
protected static function parseCommand($command)
122122
{
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');
129132
}
130133

131134
public static function getControllerMethods($class)

0 commit comments

Comments
 (0)