@@ -54,9 +54,9 @@ class Task
54
54
/**
55
55
* task status.
56
56
*
57
- * @var string
57
+ * @var string|null
58
58
*/
59
- protected $ status = '' ;
59
+ protected $ status = null ;
60
60
61
61
/**
62
62
* current use driver.
@@ -212,15 +212,13 @@ protected function afterRun($success)
212
212
*
213
213
* @param $name
214
214
*
215
- * @throws TaskBalancerException
216
- *
217
215
* @return bool
218
216
*/
219
217
public function runDriver ($ name )
220
218
{
221
219
$ driver = $ this ->getDriver ($ name );
222
220
if (!$ driver ) {
223
- throw new TaskBalancerException ( " Don`t found driver [ $ name ] in task [ $ this -> name ], please define it for current task " ) ;
221
+ return false ;
224
222
}
225
223
$ this ->currentDriver = $ driver ;
226
224
// before run a driver,
@@ -291,14 +289,10 @@ public function getNextBackupDriverName()
291
289
if (($ currentKey + 1 ) < count ($ drivers )) {
292
290
return $ drivers [$ currentKey + 1 ];
293
291
}
294
-
295
- return ;
296
292
}
297
293
298
294
/**
299
- * get a driver`s name by drivers` weight.
300
- *
301
- * @throws TaskBalancerException
295
+ * get a driver name by driver weight.
302
296
*
303
297
* @return mixed
304
298
*/
@@ -318,25 +312,16 @@ public function getDriverNameByWeight()
318
312
$ base = $ max ;
319
313
}
320
314
}
321
- if ($ count < 1 ) {
322
- return $ this -> driverNameRand () ;
315
+ if ($ count <= 0 ) {
316
+ return ;
323
317
}
324
318
$ number = mt_rand (0 , $ count - 1 );
325
319
foreach ($ map as $ data ) {
326
320
if ($ number >= $ data ['min ' ] && $ number < $ data ['max ' ]) {
327
321
return $ data ['driver ' ];
328
322
}
329
323
}
330
- throw new TaskBalancerException ('Get driver name by weight failed, something wrong ' );
331
- }
332
324
333
- /**
334
- * get a driver name.
335
- *
336
- * @return mixed
337
- */
338
- public function driverNameRand ()
339
- {
340
325
return array_rand (array_keys ($ this ->drivers ));
341
326
}
342
327
@@ -431,15 +416,13 @@ public function hasDriver($name)
431
416
*
432
417
* @param $name
433
418
*
434
- * @return null
419
+ * @return mixed
435
420
*/
436
421
public function getDriver ($ name )
437
422
{
438
423
if ($ this ->hasDriver ($ name )) {
439
424
return $ this ->drivers [$ name ];
440
425
}
441
-
442
- return ;
443
426
}
444
427
445
428
/**
@@ -477,7 +460,7 @@ public function isRunning()
477
460
*/
478
461
public function reset ()
479
462
{
480
- $ this ->status = '' ;
463
+ $ this ->status = null ;
481
464
$ this ->results = null ;
482
465
483
466
return $ this ;
@@ -604,8 +587,6 @@ public function __get($name)
604
587
if (array_key_exists ($ name , $ this ->drivers )) {
605
588
return $ this ->drivers [$ name ];
606
589
}
607
-
608
- return ;
609
590
}
610
591
611
592
/**
0 commit comments