本文整理汇总了PHP中Queue::later方法的典型用法代码示例。如果您正苦于以下问题:PHP Queue::later方法的具体用法?PHP Queue::later怎么用?PHP Queue::later使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue::later方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pFilter
private function pFilter($filter)
{
$this->info('Filter: #' . $filter->id . ' count:' . $filter->count . ' search offset: ' . $filter->search_offset . ' founded:' . $filter->users->count());
$this->info(print_r($filter->filter, true));
switch ($this->ask('action: ')) {
case 'd':
$filter->count = 1000;
$filter->save();
$this->info('deleted');
break;
case "r":
$id = $filter->id;
$date = Carbon::now()->addSecond(5);
\Queue::later($date, function ($job) use($id) {
$job->delete();
\Artisan::call('fetch:filter', ['id' => $id]);
});
$this->info('Run filter');
break;
case "m":
$filter->attachFromLoad($filter->users()->count());
$this->info('Attached: ' . $filter->users()->count());
break;
}
}
示例2: later
public function later($time, $view, $data)
{
if ($this->driver == 'laravel') {
Queue::later($time, $view, $data, function ($message) use($data) {
$message->to($data['to'])->from($data['from'])->subject($data['subject']);
});
}
}
示例3: startFetchingFilter
private function startFetchingFilter($_filter)
{
$id = $_filter->id;
$date = Carbon::now()->addSecond(1);
\Queue::later($date, function ($job) use($id) {
$job->delete();
\Artisan::call('fetch:filter', ['id' => $id]);
});
}
示例4: post
public function post()
{
if (Input::has('api_key') && Input::has('content')) {
$api_key = Input::get('api_key');
$content = Input::get('content');
$settings = Settings::where('api_key', '=', $api_key)->first();
$user_id = $settings->user_id;
$default_networks = json_decode($settings->default_networks, true);
$schedule = Carbon::now();
if (Input::has('queue')) {
$schedule_id = $settings->schedule_id;
$interval = Schedule::find($schedule_id);
if ($interval->rule == 'add') {
$schedule = $current_datetime->modify('+ ' . $interval->period);
} else {
if ($interval->rule == 'random') {
$current_day = date('d');
$from_datetime = Carbon::now();
$to_datetime = $from_datetime->copy()->modify('+ ' . $interval->period);
$days_to_add = $from_datetime->diffInDays($to_datetime);
$day = mt_rand($current_day, $current_day + $days_to_add);
$hour = mt_rand(1, 23);
$minute = mt_rand(0, 59);
$second = mt_rand(0, 59);
//year, month and timezone is null
$schedule = Carbon::create(null, null, $day, $hour, $minute, $second, null);
}
}
if (empty($schedule)) {
$schedule = $current_datetime->addHours(1);
}
}
if (!empty($default_networks)) {
$post = new Post();
$post->user_id = $user_id;
$post->content = $content;
$post->date_time = $schedule;
$post->save();
$post_id = $post->id;
foreach ($default_networks as $network_id) {
$post_network = new PostNetwork();
$post_network->user_id = $user_id;
$post_network->post_id = $post_id;
$post_network->network_id = $network_id;
$post_network->status = 1;
$post_network->save();
}
Queue::later($schedule, 'SendPost@fire', array('post_id' => $post_id));
$response_data = array('type' => 'success', 'text' => 'Your post was scheduled! It will be published on ' . $schedule->format('l jS \\o\\f F \\a\\t h:i A'));
return $response_data;
}
}
}
示例5: confirmRefundOrderById
public function confirmRefundOrderById($orderId, $data)
{
$time = time();
$errCode = 0;
$errMsg = '';
\DB::beginTransaction();
do {
try {
$order = RefundModel::find($orderId);
if (!$order) {
throw new PayException(ErrCode::ERR_ORDER_NO_EXISTS);
} elseif ($order->status == RefundModel::STATUS_SUCCESS) {
$errCode = 1;
break;
}
if (isset($data['ser_refund_no']) && !empty($data['ser_refund_no'])) {
$order->ser_refund_no = $data['ser_refund_no'];
}
if (isset($data['notify_log'])) {
$order->ser_notify_log = $data['notify_log'];
}
if (isset($data['notify_status'])) {
$order->ser_notify_status = $data['notify_status'];
}
if (isset($data['seller_partner'])) {
$order->seller_partner = $data['seller_partner'];
}
$order->refund_time = $data['refund_time'];
$order->ser_notify_time = $data['notify_time'];
$order->save();
AccountBiz::getInstance()->updateUserAccount($order->user_id, RefundModel::DEAL_OUT_REFUND, $order->refund_amount, $order->channel);
} catch (\Exception $e) {
$errCode = 1;
}
} while (0);
if ($errCode == 0) {
\DB::commit();
if (true !== BusiNotifyBiz::getInstance()->notifyCallback($order, 'refund')) {
\Queue::later(5, '\\Pay\\Service\\Queue\\BusiNotifyQueue', ['id' => $order->id, 'notify_type' => 'refund']);
}
return true;
} else {
\DB::rollback();
return false;
}
}
示例6: store
public function store()
{
$limit = 2;
if (!Input::has('number')) {
return $this->respondInsufficientPrivileges('No car number');
}
$number = Input::get('number');
$car = Car::where('number', $number)->first();
if (!$car) {
return $this->respondNotFound('Car not found');
}
$user = $car->user;
if (!$user) {
return $this->respondNotFound('User not found');
}
if ($user == $this->user) {
return $this->respondInsufficientPrivileges('Cant send to yourself');
}
$emergency = new Emergency(['sender' => $this->user->id, 'receiver' => $user->id, 'number' => $car->number, 'created_at' => Carbon::now(), 'status' => 'отправлено']);
$emergency->sender_phone = $this->user->phone->number;
//FIXME later add custom error to apicontroller
if ($this->user->urgent_calls == 0) {
return Response::json(['error' => ['message' => 'Вы исчерпали лимит срочных вызовов (' . $limit . ' в день)', 'status_code' => 1003]], 403);
}
$this->user->urgent_calls--;
$this->user->emergencies()->save($emergency);
$this->user->save();
Queue::later(30, 'smsSender', $emergency);
Queue::later(60, 'smsChecker', $emergency->id);
$response['emergencies'] = ['id' => $emergency->id, 'sender' => $emergency->sender, 'created_at' => $emergency->created_at, 'number' => $emergency->number, 'phone_number' => $emergency->sender_phone, 'delivered_at' => $emergency->delivered_at, 'status' => $emergency->status, 'via_sms' => false, 'complained_at' => $emergency->complained_at, 'failed' => $emergency->failed];
$response['tries'] = $this->user->urgent_calls;
$urgentCalls = $this->user->urgent_calls;
$emergency->phone_number = (int) $this->user->phone->number;
$emergency->receiverU->devices->each(function ($device) use($emergency, $urgentCalls) {
$stateSender = new StateSender($device->auth_token);
$stateSender->setEmergencyAdded($emergency, $urgentCalls);
$stateSender->send();
});
// Probably wiser to send state to self as well, and show only by response from state
// $emergency->getMembersTokens()->each(function ($token) use($emergency, $urgentCalls) {
// $stateSender = new StateSender($token->auth_token);
// $stateSender->setEmergencyAdded($emergency, $this->user->urgent_calls);
// $stateSender->send();
// });
return $this->respond($response);
}
示例7: test1
public function test1()
{
$this->app->config['queue'] = $this->getBaseConfig([]);
$this->app->config['database'] = $this->getDatabaseConfig();
$this->app->config['app'] += ['cipher' => 'AES-256-CBC'];
$this->app->register('DenisMilovanov\\LaravelQueueMbus\\LaravelQueueMbusServiceProvider');
$queue = 'test_queue';
$job = 'add';
Queue::purge($queue);
$max = 3;
$delay = 4;
$delayOnce = 2;
// push 1, 2, 3, ... $max - 1
foreach (range(1, $max - 1) as $i) {
Queue::push($job, ['num' => $i], $queue);
}
// $max delayed
Queue::later($delay, $job, ['num' => $max], $queue);
$count = 0;
$releasedOnce = false;
$start = time();
// select 1, 2, 3, ... $max
Queue::subscribe($queue, function (MbusJob $job) use(&$count, $max, $queue, &$finish, &$releasedOnce, $delayOnce) {
// let's delay the last one yet another time
if (!$releasedOnce and $count == $max - 1) {
$releasedOnce = true;
$job->release($delayOnce);
return;
}
$count++;
$this->assertTrue($job->getRawBody()['data']['num'] == $count);
if ($count == $max) {
Queue::unsubscribe($queue);
$finish = time();
}
});
// check delay
$this->assertTrue($finish - $start >= $delay + $delayOnce);
}
示例8: sendMail
public static function sendMail($incomingMail, $view, $delay)
{
$callback = MailWorker::buildQueueCallable(function ($m) use($incomingMail) {
$m->from($incomingMail->fromAddress, $incomingMail->fromName);
foreach ($incomingMail->to as $key => $value) {
$m = $m->to($key, $value);
}
foreach ($incomingMail->cc as $key => $value) {
$m = $m->cc($key);
}
foreach ($incomingMail->replyTo as $key => $value) {
$m = $m->replyTo($key);
}
$m->subject($incomingMail->subject);
foreach ($incomingMail->attachments as $attachment) {
$m->attach($attachment->filePath, array('as' => $attachment->name . "." . $attachment->extName));
}
\Log::info('The mail "' . $incomingMail->subject . '" was sent.');
});
$data = array('incomingMail' => $incomingMail);
\Queue::later($delay, '\\DavinBao\\Mailbox\\MailWorker@handleQueuedMessage', compact('view', 'data', 'callback'), 'low');
}
示例9: getCancel
public function getCancel($user, $token)
{
switch ($token) {
case 'now':
$this->runCancel('', array('id' => $user->id));
break;
case 'later':
$date = Carbon::now()->addMinutes(15);
Queue::later($date, 'UserController@runCancel', array('id' => $user->id));
break;
case 'tomorrow':
$date = Carbon::tomorrow();
Queue::later($date, 'UserController@runCancel', array('id' => $user->id));
break;
case 'disable':
if ($user->cancelled) {
DB::table('users')->where('id', $user->id)->update(array('confirmed' => true, 'cancelled' => false));
}
break;
}
Activity::log(array('contentID' => $user->id, 'contentType' => 'account_cancelled', 'description' => $user->id, 'details' => '', 'updated' => $user->id));
return Redirect::to('user')->with('success', Lang::get('user/user.user_account_updated'));
}
示例10: confirmTransOrderById
public function confirmTransOrderById($orderId, $data)
{
$errCode = 0;
$errMsg = '';
\DB::beginTransaction();
do {
try {
$order = TransModel::find($orderId);
if (!$order) {
throw new PayException(ErrCode::ERR_ORDER_NO_EXISTS);
} elseif ($order->status == TransModel::STATUS_SUCCESS) {
$errCode = 1;
break;
}
if (isset($data['ser_trans_no'])) {
$order->ser_trans_no = $data['ser_trans_no'];
}
if (isset($data['ser_notify_log'])) {
$order->ser_notify_log = $data['ser_notify_log'];
}
$order->ser_notify_status = $data['ser_notify_status'];
$order->pay_time = $data['ser_pay_time'];
$order->ser_notify_time = $data['ser_pay_time'];
$order->save();
} catch (\Exception $e) {
$errCode = 1;
}
} while (0);
if ($errCode == 0) {
\DB::commit();
\Queue::later(5, '\\Pay\\Service\\Queue\\BusiNotifyQueue', ['id' => $order->id, 'notify_type' => 'trans']);
return true;
} else {
\DB::rollback();
return false;
}
}
示例11: generateImage
/**
* Generate an album image from a Last.fm URL
*
* @param string $url URL of Last.fm album image
* @param mixed $error Error message string
*
* @return mixed
*/
public function generateImage($url, $error = false)
{
$this->filenameSansPath = $this->username . '_' . $this->number . '_' . $this->result['playcount'] . '_' . md5($this->result['name']) . '.png';
$this->filename = public_path() . '/' . $this->filenameSansPath;
if (Cache::has($this->filename)) {
if (file_exists($this->filename)) {
Log::info('Loaded cached object', ['file' => $this->filenameSansPath]);
$image = Image::open($this->filename);
return $image->encode($this->filename, 90);
}
}
if ($error) {
// Normally, you'd only come down this path if the function was called by something else forcing an error
Log::error('There was an error, generate the error image');
// We had an error, we're a sad panda
$image = Image::make(public_path() . '/resources/sadpanda.png');
} else {
// Pull image from Last.fm and create the Image instance
try {
$image = Image::make($url);
} catch (Exception $e) {
Log::error('Image path is invalid', ['message' => 'Error: ' . $e->getMessage(), 'url' => $url, 'code' => $e->getCode()]);
// Go back and generate the error image
return $this->generateImage(false, 'Unable to locate image');
}
// Resize image to 300x300 px, just in case the image is too large/small
$image->resize(300, 300);
}
// Expand image up 36px with the background color with white
$image->resizeCanvas(0, 36, 'bottom', true, $this->text['colours']['white']);
// Larger rectangle that forms the border
$image->rectangle($this->text['colours']['border'], 0, 0, 299, 24, false);
// Smaller rectangle with the background
$image->rectangle($this->text['colours']['background'], 1, 1, 298, 23);
if ($error) {
$image->text('Error: ' . $error, 7, 17, $this->text['size'], $this->text['colours']['black'], 0, $this->text['fonts']['bold']);
} else {
$x = 0;
// 1. or 2. (etc)
$image->text($this->number . '.', $x += 7, 17, $this->text['size'], $this->text['colours']['black'], 0, $this->text['fonts']['bold']);
$bbox = imagettfbbox($this->text['size'], 0, $this->text['fonts']['bold'], $this->number . '.');
// Artist Name
$image->text($this->result['artist']['name'], $x += $bbox[2] += 4, 17, $this->text['size'], $this->text['colours']['link'], 0, $this->text['fonts']['normal']);
$bbox = imagettfbbox($this->text['size'], 0, $this->text['fonts']['normal'], $this->result['artist']['name']);
// Chuck in a dash
$image->text('-', $x += $bbox[2] += 6, 17, $this->text['size'], $this->text['colours']['black'], 0, $this->text['fonts']['normal']);
$bbox = imagettfbbox($this->text['size'], 0, $this->text['fonts']['normal'], '-');
// And the Album Title
$image->text($this->result['name'], $x += $bbox[2] += 4, 17, $this->text['size'], $this->text['colours']['link'], 0, $this->text['fonts']['bold']);
$bbox = imagettfbbox($this->text['size'], 0, $this->text['fonts']['bold'], $this->result['name']);
// And the Playcount in brackets
$image->text('(' . $this->result['playcount'] . ')', $x += $bbox[2] + 4, 17, $this->text['size'], $this->text['colours']['black'], 0, $this->text['fonts']['normal']);
// And we're done making the image
}
// Save the image as a .png with a quality of 90
$image->save($this->filename);
// I don't want to optimise the error message images
if (!$error) {
Log::info('Finished generating image non-optimised image');
if (Cache::forever($this->filename, true)) {
Log::info('Added ' . $this->filenameSansPath . ' to cache');
}
// Get a random number of seconds between 10 and 99 for the queue - I don't really want to
// start generating smaller images straight away
$seconds = mt_rand(10, 99);
Log::info('Sent image to optimiser queue, starting in ' . $seconds . ' seconds');
// Send the image to the optimiser for the next requests...
Queue::later($seconds, 'LastfmController@optimiseImage', ['image' => $this->filename, 'level' => 2]);
}
return $image;
}
示例12: confirmConsumeOrderById
public function confirmConsumeOrderById($orderId)
{
$time = time();
$errCode = 0;
$errMsg = '';
\DB::beginTransaction();
do {
try {
$order = ConsumeModel::find($orderId);
if (!$order) {
throw new PayException(ErrCode::ERR_ORDER_NO_EXISTS);
} elseif ($order->status == ConsumeModel::STATUS_SUCCESS) {
$errCode = 1;
break;
}
$order->status = ConsumeModel::STATUS_SUCCESS;
$order->pay_time = $time;
$order->update_time = $time;
$order->save();
AccountBiz::getInstance()->updateUserAccount($order->user_id, ConsumeModel::DEAL_CONSUME, $order->consume_amount, $order->channel);
} catch (\Exception $e) {
$errCode = 2;
}
} while (0);
if ($errCode == 0) {
\DB::commit();
if (true !== BusiNotifyBiz::getInstance()->notifyCallback($order, 'consume')) {
\Queue::later(5, '\\Pay\\Service\\Queue\\BusiNotifyQueue', ['id' => $order->id, 'notify_type' => 'consume']);
}
return true;
} else {
\DB::rollback();
return false;
}
}
示例13: createPost
public function createPost()
{
$user_id = Auth::user()->id;
$rules = array('content' => 'required');
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
if (Input::has('ajax')) {
return array('type' => 'danger', 'messages' => $validator->messages());
} else {
return Redirect::to('/post/new')->withErrors($validator)->withInput();
}
}
$content = Input::get('content');
$post_now = Input::get('post_now');
$schedule_type = Input::get('schedule');
if (empty($schedule_type)) {
$schedule_type = Setting::where('user_id', '=', $user_id)->pluck('schedule_id');
}
$schedule_id = Settings::where('user_id', '=', $user_id)->pluck('schedule_id');
$current_datetime = Carbon::now();
$schedule = Carbon::now();
if ($post_now == '0' && $schedule_type != 'custom') {
$schedule_id = $schedule_type;
$interval = Schedule::find($schedule_id);
if ($interval->rule == 'add') {
$schedule = $current_datetime->modify('+ ' . $interval->period);
} else {
if ($interval->rule == 'random') {
$current_day = date('d');
$from_datetime = Carbon::now();
$to_datetime = $from_datetime->copy()->modify('+ ' . $interval->period);
$days_to_add = $from_datetime->diffInDays($to_datetime);
$day = mt_rand($current_day, $current_day + $days_to_add);
$hour = mt_rand(1, 23);
$minute = mt_rand(0, 59);
$second = mt_rand(0, 59);
//year, month and timezone is null
$schedule = Carbon::create(null, null, $day, $hour, $minute, $second, null);
}
}
if (empty($schedule)) {
$schedule = $current_datetime->addHours(1);
}
} else {
$schedule = Carbon::parse(Input::get('schedule_value'));
}
$networks = Input::get('network');
if (empty($networks)) {
$networks = Setting::where('user_id', '=', $user_id)->pluck('default_networks');
$networks = json_decode($networks, true);
}
$post = new Post();
$post->user_id = $user_id;
$post->content = $content;
$post->date_time = $schedule->toDateTimeString();
$post->save();
$post_id = $post->id;
foreach ($networks as $network_id) {
$post_network = new PostNetwork();
$post_network->user_id = $user_id;
$post_network->post_id = $post_id;
$post_network->network_id = $network_id;
$post_network->status = 1;
$post_network->save();
}
Queue::later($schedule, 'SendPost@fire', array('post_id' => $post_id));
if (Input::has('ajax')) {
return array('type' => 'success', 'text' => 'Your post was scheduled! It will be published on ' . $schedule->format('l jS \\o\\f F \\a\\t h:i A'));
}
return Redirect::to('/post/new')->with('message', array('type' => 'success', 'text' => 'Your post was scheduled! It will be published on ' . $schedule->format('l jS \\o\\f F \\a\\t h:i A')));
}
示例14: saveJob
public function saveJob()
{
$q = $this->data;
$startc = \Carbon\Carbon::parse(array_get($q, 'jobs.new.start'));
$repeat = array_get($q, 'jobs.new.repeat');
$data = (array) json_decode(array_get($q, 'jobs.new.data'), true);
$queue = array_get($q, 'jobs.new.classname');
if ($repeat > 0) {
$data['repeatJob'] = $repeat;
}
$classFullName = starts_with($queue, "\\") ? $queue : "\\Veer\\Queues\\" . $queue;
if (!class_exists($classFullName)) {
//
} else {
if (now() >= $startc) {
\Queue::push($classFullName, $data);
} else {
$wait = \Carbon\Carbon::now()->diffInMinutes($startc);
\Queue::later($wait, $classFullName, $data);
}
}
$this->actionSave = null;
}
示例15: cancelRechargeOrder
public function cancelRechargeOrder($fields)
{
$this->_rechargeModel = RechargeModel::find($fields['pay_recharge_id']);
do {
if ($this->_rechargeModel->id < 0) {
throw new PayException(ErrCode::ERR_ORDER_NO_EXISTS);
}
if ($this->_rechargeModel->status != rechargeModel::STATUS_SUCCESS) {
throw new PayException(ErrCode::ERR_ORDER_STATUS);
}
if ($this->_rechargeModel->user_id != $fields['user_id']) {
throw new PayException(ErrCode::ERR_ORDER_USER_ID);
}
if ($this->_rechargeModel->refund_count > 0) {
throw new PayException(ErrCode::ERR_REFUND, '只允许退款一次');
}
if ($fields['refund_amount'] > $this->_rechargeModel->recharge_amount) {
throw new PayException(ErrCode::ERR_REFUND, '退款金额不能大于充值金额');
}
if (!$this->_rechargeModel->ser_recharge_no) {
throw new PayException(ErrCode::ERR_REFUND, '该订单不允许通过接口退款');
}
} while (0);
$fields['recharge_id'] = $this->_rechargeModel->id;
$fields['gateway'] = $this->_rechargeModel->gateway;
$fields['seller_partner'] = $this->_rechargeModel->seller_partner;
$refundModel = RefundBiz::getInstance()->createRefundOrder($fields);
$this->refundRechargeOrderById($this->_rechargeModel->id, $refundModel->amount);
\Queue::later(30, '\\Pay\\Service\\Queue\\SerAutoConfirmQueue@serRefund', ['id' => $refundModel->id]);
return ['user_id' => $this->_rechargeModel->user_id, 'refund_amount' => $refundModel->amount, 'pay_recharge_id' => $this->_rechargeModel->id];
}