$task->beforeRun(function ($task, $preReturn, $index, $handlers) { print_r("before run ---{$preReturn}-----{$index}<br>"); return 11; }); $task->beforeRun(function ($task, $preReturn, $index, $handlers) { print_r("before run ---{$preReturn}-----{$index}<br>"); return 22; }, false); $task->beforeRun(function ($task, $preReturn, $index, $handlers) { print_r("before run ---{$preReturn}-----{$index}<br>"); }); $task->hook('beforeDriverRun', function ($task, $preReturn, $index, $handlers) { print_r("before driver run ---{$preReturn}-----{$index}<br>"); return [1]; }); $task->hook('beforeDriverRun', function ($task, $preReturn, $index, $handlers) { print_r("before driver run ---" . implode(',', $preReturn) . "-----{$index}<br>"); return [1, 2]; }, true); $task->hook('beforeDriverRun', function ($task, $preReturn, $index, $handlers) { print_r("before driver run ---" . implode(',', $preReturn) . "-----{$index}<br>"); return [1, 2, 3]; }); $task->afterRun(function ($task, $results, $preReturn, $index, $handlers) { print_r("after run --------!<br>"); }); }); //run task: $result = Balancer::run('task1', $data); print_r('<br>'); print_r($result);
/** * Start send SMS/voice verify. * * If give a true parameter, this system will immediately start request to send SMS/voice verify whatever whether to use the queue. * if you are already pushed sms instance to the queue, you can recall the method `send()` in queue system without `true` parameter, * so this mechanism in order to make you convenient use the method `send()` in queue system. * * @param bool $immediately * * @return mixed */ public function send($immediately = false) { if (!self::$enableQueue || $this->pushedToQueue) { $immediately = true; } if ($immediately) { $result = Balancer::run(self::TASK_NAME, ['data' => $this->getData(), 'driver' => $this->firstAgent]); } else { $result = $this->push(); } return $result; }
/** * start send * * @param bool $immediately * * @return mixed */ public function send($immediately = false) { $this->validator(); // if disable push to queue, // send the sms immediately. if (!self::$enableQueue) { $immediately = true; } // whatever 'PhpSms' whether to enable or disable push to queue, // if you are already pushed sms instance to queue, // you can recall the method `send()` in queue job without `true` parameter. // // So this mechanism in order to make you convenient use the method `send()` in queue system. if ($this->pushedToQueue) { $immediately = true; } // whether to send sms immediately, // or push it to queue. if ($immediately) { $result = Balancer::run(self::TASK, ['data' => $this->getData(), 'agent' => $this->firstAgent]); } else { $result = $this->push(); } return $result; }
})->data(['this is data 2']); $task->driver('driver_3')->weight(0)->backUp()->data(['this is data 3'])->work(function ($driver, $data) { $driver->success(); print_r('run work! by ' . $driver->name . '<br>'); return ['test.driver3 working', $data]; }); $task->beforeRun(function ($task) { print_r('before run --------!<br>'); }); $task->afterRun(function ($task, $results) { print_r('after run --------!<br>'); }); }); //run task: $data['age'] = '25'; $result = Balancer::run('test1', $data); print_r('<br>resuts data:<br>'); var_dump($result); print_r('<hr>task object:<br>'); var_dump($t); class Person { protected $name; protected $age; public function __construct($name, $age) { $this->name = $name; $this->age = $age; } public function toString() {
/** * start send * @param bool $force * @return mixed * @throws \Exception */ public function send($force = false) { $this->validator(); $results = null; if (!self::$enableQueue) { $force = true; } if ($force) { $results = Balancer::run(self::TASK, $this->getData()); } else { $results = $this->push(); } return $results; }