コード例 #1
0
ファイル: FileService.php プロジェクト: nmpribeiro/Media
 /**
  * Create the necessary thumbnails for the given file
  * @param $savedFile
  */
 private function createThumbnails($savedFile)
 {
     $this->queue->push(function (Job $job) use($savedFile) {
         app('imagy')->createAll($savedFile->path);
         $job->delete();
     });
 }
コード例 #2
0
ファイル: HybridQueue.php プロジェクト: halaei/hybrid-queue
 /**
  * Push a new job onto the queue after a delay.
  *
  * @param  \DateTime|int $delay
  * @param  string $job
  * @param  mixed $data
  * @param  string $queue
  * @return mixed
  */
 public function later($delay, $job, $data = '', $queue = null)
 {
     if ($this->isLongTerm($delay)) {
         return $this->longTermQueue->later($this->longTermDelay($delay), new HybridJob($job, $data, $this->shortTermDelay($delay), $this->shortTermConnection, $queue), '', $queue);
     }
     return $this->shortTermQueue->later($delay, $job, $data, $queue);
 }
コード例 #3
0
ファイル: Factory.php プロジェクト: docit/git-hook
 public function createSyncJob($project)
 {
     if ($project instanceof Project) {
         $project = $project->getName();
     }
     $this->queue->push(SyncProject::class, compact('project'));
 }
 /**
  * Queue a new push notification for sending.
  * 
  * @param AbstractPayload $payload
  * @param array $tokens
  * @param string $queue
  */
 public function queue(Payload $payload, $tokens, $queue = null)
 {
     //Serialize data
     $payload = serialize($payload);
     $tokens = serialize($tokens);
     //Push in queue
     return $this->queue->push('bridge@handleQueuedSending', compact('payload', 'tokens'), $queue);
 }
コード例 #5
0
ファイル: Dispatcher.php プロジェクト: ahead4/bus
 /**
  * Push the command onto the given queue instance.
  *
  * @param  \Illuminate\Contracts\Queue\Queue  $queue
  * @param  mixed  $command
  * @return mixed
  */
 protected function pushCommandToQueue($queue, $command)
 {
     if (isset($command->queue, $command->delay)) {
         return $queue->laterOn($command->queue, $command->delay, $command);
     }
     if (isset($command->queue)) {
         return $queue->pushOn($command->queue, $command);
     }
     if (isset($command->delay)) {
         return $queue->later($command->delay, $command);
     }
     return $queue->push('Ahead4\\Bus\\CallQueuedHandler@call', ['pipes' => $this->pipes, 'command' => serialize($command)]);
 }
コード例 #6
0
 /**
  * Upload Pdf to s3 and create contracts
  *
  * @param $key
  */
 public function uploadPdfToS3AndCreateContracts($key)
 {
     $contracts = $this->getJsonData($key);
     foreach ($contracts as $contract) {
         $this->updateContractJsonByID($key, $contract->id, ['create_status' => static::CREATE_PROCESSING], 2);
         try {
             $this->storage->disk('s3')->put($contract->file, $this->filesystem->get($this->getFilePath($key, $contract->file)));
         } catch (Exception $e) {
             $this->logger->error(sprintf('File could not be uploaded : %s', $e->getMessage()));
             continue;
         }
         $data = ['file' => $contract->file, 'filehash' => $contract->filehash, 'user_id' => $contract->user_id, 'metadata' => $contract->metadata];
         try {
             $con = $this->contract->save($data);
             $this->logger->activity('contract.log.save', ['contract' => $con->id], $con->id, $con->user_id);
             $this->updateContractJsonByID($key, $contract->id, ['create_status' => static::CREATE_COMPLETED], 2);
             if ($con) {
                 $this->queue->push('App\\Nrgi\\Services\\Queue\\ProcessDocumentQueue', ['contract_id' => $con->id]);
             }
             $this->logger->info('Contract successfully created.', ['Contract Title' => $con->title]);
         } catch (Exception $e) {
             $this->logger->error($e->getMessage());
             if ($this->storage->disk('s3')->exists($contract->file)) {
                 $this->storage->disk('s3')->delete($contract->file);
             }
             $this->updateContractJsonByID($key, $contract->id, ['create_remarks' => trans('contract.save_fail'), 'create_status' => static::CREATE_FAILED], 2);
         }
         $this->deleteFile($key, $contract->file);
     }
 }
コード例 #7
0
ファイル: Mailer.php プロジェクト: bryanashley/framework
 /**
  * Queue a new e-mail message for sending after (n) seconds.
  *
  * @param  int  $delay
  * @param  string|array  $view
  * @param  array  $data
  * @param  \Closure|string  $callback
  * @param  string|null  $queue
  * @return mixed
  */
 public function later($delay, $view, array $data = [], $callback = null, $queue = null)
 {
     if ($view instanceof MailableContract) {
         return $view->later($delay, $this->queue);
     }
     return $this->queue->laterOn($queue, $delay, new Jobs\HandleQueuedMessage($view, $data, $callback));
 }
コード例 #8
0
 /**
  * Update Contract status
  *
  * @param $id
  * @param $status
  * @param $type
  * @return bool
  */
 public function updateStatus($id, $status, $type)
 {
     try {
         $contract = $this->contract->findContract($id);
     } catch (ModelNotFoundException $e) {
         $this->logger->error('Contract not found', ['contract id' => $id]);
         return false;
     } catch (Exception $e) {
         $this->logger->error($e->getMessage());
         return false;
     }
     if ($contract->isEditableStatus($status)) {
         $status_key = sprintf('%s_status', $type);
         $old_status = $contract->{$status_key};
         $contract->{$status_key} = $status;
         $contract->save();
         if ($status == Contract::STATUS_PUBLISHED) {
             $this->queue->push('App\\Nrgi\\Services\\Queue\\PostToElasticSearchQueue', ['contract_id' => $id, 'type' => $type], 'elastic_search');
         }
         $this->logger->activity('contract.log.status', ['type' => $type, 'old_status' => $old_status, 'new_status' => $status], $contract->id);
         $this->logger->info("Contract status updated", ['Contract id' => $contract->id, 'Status type' => $type, 'Old status' => $old_status, 'New Status' => $status]);
         return true;
     }
     return false;
 }
コード例 #9
0
ファイル: Queues.php プロジェクト: arrounded/queues
 /**
  * @param JobDescription $job
  *
  * @return void
  */
 protected function queue(JobDescription $job)
 {
     if ($this->disabled) {
         return;
     }
     if ($job->isDelayed()) {
         return $this->queue->later($job->getDelay(), $job->getClass(), $job->getPayload(), $job->getQueue());
     }
     return $this->queue->push($job->getClass(), $job->getPayload(), $job->getQueue());
 }
コード例 #10
0
ファイル: Mailer.php プロジェクト: HydrefLab/laravel-mailer
 /**
  * @param string $queue
  * @param string|null $subject
  * @param string|null $template
  * @return bool
  */
 public function queue($queue, $subject = null, $template = null)
 {
     if (null !== $subject) {
         $this->setSubject($subject);
     }
     if (null !== $template) {
         $this->setTemplate($template);
     }
     $this->queue->pushOn($queue, new Job($this->getData()));
     return true;
 }
コード例 #11
0
 /**
  * @param $annotationStatus
  * @param $contractId
  * @return bool
  */
 public function updateStatus($annotationStatus, $contractId)
 {
     $status = $this->annotation->updateStatus($annotationStatus, $contractId);
     if ($status) {
         if ($annotationStatus == Annotation::PUBLISHED) {
             $this->queue->push('App\\Nrgi\\Services\\Queue\\PostToElasticSearchQueue', ['contract_id' => $contractId, 'type' => 'annotation'], 'elastic_search');
         }
         $this->logger->activity("annotation.status_update", ['status' => $annotationStatus], $contractId);
         $this->logger->info('Annotation status updated.', ['Contract id' => $contractId, 'status' => $annotationStatus]);
     }
     return $status;
 }
コード例 #12
0
ファイル: FetchImages.php プロジェクト: syamantak/imgubox
 /**
  * Execute the command.
  *
  * @return void
  */
 public function handle(Container $app, Queue $queue)
 {
     $imgurIds = $this->user->logs->lists('imgur_id');
     $imgurToken = $this->user->imgurToken;
     // Setup Imgur Service
     $imgur = $app->make('ImguBox\\Services\\ImgurService');
     $imgur->setUser($this->user);
     $imgur->setToken($imgurToken);
     $difference = $imgurToken->updated_at->diffInSeconds();
     // Imgur acccess_token expires after 3600 seconds
     if ($difference >= 3500) {
         $refreshedToken = $imgur->refreshToken();
         if (property_exists($refreshedToken, 'success') && $refreshedToken->success === false) {
             return $this->error('something went wrong');
         }
         $imgurToken->token = \Crypt::encrypt($refreshedToken->access_token);
         $imgurToken->save();
     }
     $imgur->setToken($imgurToken);
     $favorites = $imgur->favorites();
     if (is_array($favorites)) {
         // Remove models we already processed
         $favorites = collect($favorites)->reject(function ($object) use($imgurIds) {
             return in_array($object->id, $imgurIds);
         });
         foreach ($favorites as $favorite) {
             Cache::put("user:{$this->user->id}:favorite:{$favorite->id}", $favorite, 10);
             $job = new StoreImages($this->user->id, $favorite->id);
             $queue->later(rand(1, 900), $job);
         }
     } elseif (property_exists($favorites, 'error')) {
         Mail::send('emails.api-error', [], function ($message) {
             $message->to($this->user->email)->subject("ImguBox can no longer synx your Imgur favorites. Action needed.");
         });
         // Delete ImgurToken.
         $imgurToken->delete();
     }
 }
コード例 #13
0
 /**
  * webhook
  *
  * @param $type
  * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
  */
 public function webhook()
 {
     $headers = ['delivery' => $this->request->header('x-github-delivery'), 'event' => $this->request->header('x-github-event'), 'user-agent' => $this->request->header('user-agent'), 'signature' => $this->request->header('x-hub-signature')];
     $payload = $this->request->all();
     $repo = strtolower($payload['repository']['full_name']);
     foreach ($this->factory->getProjects() as $project) {
         if ($project->config('enable_github_hook', false) === false || $project->config('github_hook_settings.sync.enabled', false) === false) {
             continue;
         }
         $config = $project->config('github_hook_settings');
         $projectRepo = $project->config('github_hook_settings.owner') . '/' . $project->config('github_hook_settings.repository');
         if ($repo !== $projectRepo) {
             continue;
         }
         $hash = hash_hmac('sha1', file_get_contents("php://input"), $project->config('github_hook_settings.sync.webhook_secret'));
         if ($headers['signature'] === "sha1={$hash}") {
             $this->queue->push(\Docit\Hooks\Github\Commands\GithubSyncProject::class, ['project' => $project->getName()]);
             return response('', 200);
         } else {
             return response('Invalid hash', 403);
         }
     }
     return response('', 500);
 }
コード例 #14
0
 /**
  * Create new task
  *
  * @param $contract_id
  * @return bool
  */
 public function create($contract_id)
 {
     $contract = $this->contract->findWithPages($contract_id);
     try {
         $this->task->createTasks($contract->pages);
         $this->logger->info('Tasks added in database', ['Contract_id' => $contract_id]);
     } catch (Exception $e) {
         $this->logger->error('createTasks:' . $e->getMessage(), ['Contract_id' => $contract_id]);
         return false;
     }
     try {
         $contract->mturk_status = Contract::MTURK_SENT;
         $contract->save();
     } catch (Exception $e) {
         $this->logger->error('save:' . $e->getMessage(), ['Contract_id' => $contract->id]);
         return false;
     }
     $this->logger->activity('mturk.log.create', ['contract' => $contract->title], $contract->id);
     $this->queue->push('App\\Nrgi\\Mturk\\Services\\Queue\\MTurkQueue', ['contract_id' => $contract->id], 'mturk');
     return true;
 }
コード例 #15
0
ファイル: Dispatcher.php プロジェクト: focuslife/v0.1
 /**
  * Push the command onto the given queue instance.
  *
  * @param  \Illuminate\Contracts\Queue\Queue  $queue
  * @param  mixed  $command
  * @return mixed
  */
 protected function pushCommandToQueue($queue, $command)
 {
     if (isset($command->queue, $command->delay)) {
         return $queue->laterOn($command->queue, $command->delay, $command);
     }
     if (isset($command->queue)) {
         return $queue->pushOn($command->queue, $command);
     }
     if (isset($command->delay)) {
         return $queue->later($command->delay, $command);
     }
     return $queue->push($command);
 }
コード例 #16
0
 public function it_pushes_mail_to_queue(Queue $queue)
 {
     $recipient = new Recipient('Jane Doe', '*****@*****.**');
     $variableOne = new Variable('global_one', 'Example');
     $variableTwo = new Variable('global_two', 'Another example');
     $variableThree = new Variable('local', 'Yet another example');
     $attachment = new Attachment('text/csv', 'test.csv', 'example;test;');
     $data = ['from_name' => 'John Doe', 'from_email' => '*****@*****.**', 'subject' => 'Example subject', 'template' => 'example template', 'recipients' => [new Recipient('Jane Doe', '*****@*****.**')], 'global_vars' => ['global_one' => ['name' => 'GLOBAL_ONE', 'content' => 'Example'], 'global_two' => ['name' => 'GLOBAL_TWO', 'content' => 'Another example']], 'local_vars' => ['*****@*****.**' => ['local' => ['name' => 'LOCAL', 'content' => 'Yet another example']]], 'headers' => [], 'attachments' => [['type' => 'text/csv', 'name' => 'test.csv', 'content' => 'ZXhhbXBsZTt0ZXN0Ow==']]];
     $this->setSubject('Example subject');
     $this->setTemplate('example template');
     $this->addRecipient($recipient);
     $this->addGlobalVariable($variableOne);
     $this->addGlobalVariable($variableTwo);
     $this->addLocalVariable($recipient, $variableThree);
     $this->addAttachment($attachment);
     $job = new Job($data);
     $queue->pushOn('mandrill', $job)->shouldBeCalled();
     $this->queue('mandrill')->shouldReturn(true);
 }
コード例 #17
0
ファイル: Worker.php プロジェクト: bryanashley/framework
 /**
  * Get the next job from the queue connection.
  *
  * @param  \Illuminate\Contracts\Queue\Queue  $connection
  * @param  string  $queue
  * @return \Illuminate\Contracts\Queue\Job|null
  */
 protected function getNextJob($connection, $queue)
 {
     try {
         foreach (explode(',', $queue) as $queue) {
             if (!is_null($job = $connection->pop($queue))) {
                 return $job;
             }
         }
     } catch (Exception $e) {
         $this->exceptions->report($e);
     } catch (Throwable $e) {
         $this->exceptions->report(new FatalThrowableError($e));
     }
 }
コード例 #18
0
 /**
  * Get the next job from the queue connection.
  *
  * @param  \Illuminate\Contracts\Queue\Queue  $connection
  * @param  string  $queue
  * @return \Illuminate\Contracts\Queue\Job|null
  */
 protected function getNextJob($connection, $queue)
 {
     if (is_null($queue)) {
         return $connection->pop();
     }
     foreach (explode(',', $queue) as $queue) {
         if (!is_null($job = $connection->pop($queue))) {
             return $job;
         }
     }
 }
コード例 #19
0
ファイル: Mailer.php プロジェクト: riopurwanggono/boombazaar
 /**
  * Queue a new e-mail message for sending after (n) seconds.
  *
  * @param  int  $delay
  * @param  string|array  $view
  * @param  array  $data
  * @param  \Closure|string  $callback
  * @param  string|null  $queue
  * @return mixed
  */
 public function later($delay, $view, array $data, $callback, $queue = null)
 {
     $callback = $this->buildQueueCallable($callback);
     return $this->queue->later($delay, 'mailer@handleQueuedMessage', compact('view', 'data', 'callback'), $queue);
 }
コード例 #20
0
 /**
  * @param DomainMessage $domainMessage
  * @return void
  */
 public function handle(DomainMessage $domainMessage)
 {
     $this->queue->push(QueueToEventDispatcher::class, ['uuid' => (string) $domainMessage->getId(), 'playhead' => $domainMessage->getPlayHead(), 'metadata' => json_encode($this->serializer->serialize($domainMessage->getMetadata())), 'payload' => json_encode($this->serializer->serialize($domainMessage->getPayload())), 'recorded_on' => (string) $domainMessage->getRecordedOn(), 'type' => $domainMessage->getType()]);
 }
コード例 #21
0
 /**
  * Queue a new message for sending after (n) seconds.
  *
  * @param  int  $delay
  * @param  \Closure|string  $callback
  * @param  string  $queue
  *
  * @return mixed
  */
 public function later($delay, $callback, $queue = null)
 {
     $callback = $this->buildQueueCallable($callback);
     return $this->queue->later($delay, 'messenger@handleQueuedMessage', compact('callback'), $queue);
 }
コード例 #22
0
 /**
  * @inheritdoc
  */
 public function push($taskId, callable $task)
 {
     $this->illuminateQueue->push(IlluminateQueueHandler::class, [$taskId, $this->serializer->serialize($task)]);
 }
コード例 #23
0
 /**
  * Push command to queue.
  *
  * @param \Illuminate\Contracts\Queue\Queue $queue
  * @param \Krucas\Counter\Integration\Laravel\Commands\Base $command
  * @return void
  */
 public function queue(Queue $queue, Base $command)
 {
     if (!is_null($this->queue)) {
         $queue->pushOn($this->queue, $command);
     } else {
         $queue->push($command);
     }
 }
コード例 #24
0
 /**
  * @param $email
  */
 protected function startCooldown($email)
 {
     $seconds = $this->config->get('users.auth.throttling_interval');
     $delay = $this->carbon->now()->addSeconds($seconds);
     $this->queue->later($delay, new Cooldown($this->ip, $email));
 }
コード例 #25
0
ファイル: SMS.php プロジェクト: adetoola/sms
 /**
  * Queue a new e-mail message for sending after (n) seconds.
  *
  * @param  int  $delay
  * @param  array  $data
  * @param  \Closure|string  $callback
  * @param  string|null  $queue
  * @return mixed
  */
 public function later($delay, $recepient, $message, $queue = null)
 {
     $callback = ['recepient' => $recepient, 'message' => $message, 'sender' => isset($sender) ? $sender : null, 'message_type' => isset($message_type) ? $message_type : 0];
     return $this->queue->later($delay, 'sms@handleQueuedMessage', $callback, $queue);
 }
コード例 #26
0
ファイル: FetchUserFavs.php プロジェクト: janusnic/imgubox
 private function pushFetchImagesQueue(User $user)
 {
     $job = new FetchImages($user->id);
     $this->queue->later(rand(1, 900), $job);
 }
コード例 #27
0
 public function it_pushes_mail_to_queue(Queue $queue)
 {
     $recipient = new Recipient('Jane Doe', '*****@*****.**');
     $variableOne = new Variable('global_one', 'Example');
     $variableTwo = new Variable('global_two', 'Another example');
     $variableThree = new Variable('local', 'Yet another example');
     $data = ['from_name' => 'Master Jedi Yoda', 'from_email' => '*****@*****.**', 'subject' => 'Example subject', 'template' => 'example template', 'recipients' => ['*****@*****.**' => $recipient], 'global_vars' => ['global_one' => 'Example', 'global_two' => 'Another example'], 'local_vars' => ['*****@*****.**' => [$variableThree]], 'headers' => [], 'reply_to' => null, 'attachments' => []];
     $this->setSubject('Example subject');
     $this->setTemplate('example template');
     $this->addRecipient($recipient);
     $this->addGlobalVariable($variableOne);
     $this->addGlobalVariable($variableTwo);
     $this->addLocalVariable($recipient, $variableThree);
     $job = new Job($data);
     $queue->pushOn('sendgrid', $job)->shouldBeCalled();
     $this->queue('sendgrid')->shouldReturn(true);
 }