示例#1
0
 /**
  * Registers services for the applications
  * 
  * @param Application $app
  */
 private function registerServices(Application $app)
 {
     // Queue message for emailing task
     $app['email_message'] = function (Application $app) {
         return new EmailMessage(['mailer' => $app['mailer']]);
     };
     // To use Gmail SMTP server for mailing, use smtp transport
     $app['swiftmailer.transport'] = Swift_SmtpTransport::newInstance($app['email_host'], $app['email_port'], $app['email_encrypt'])->setUsername($app['email_username'])->setPassword($app['email_password']);
     // Register SwiftMailer with smtp transport
     $app['mailer'] = $app->share(function ($app) {
         return new Swift_Mailer($app['swiftmailer.transport']);
     });
     // Queue manager which handles queue processing
     $app['queue_manager'] = $app->share(function ($app) {
         // Set up pdo connection to the database
         $dbh = new PDO($app['db_dsn'], $app['db_user'], $app['db_password']);
         $manager = new Manager();
         // Let manager use this connection for database management
         $manager->setPdo($dbh);
         return $manager;
     });
 }
示例#2
0
 /**
  * Test what happens if no worker is free
  * @return void
  * @author Andraz <*****@*****.**>
  */
 public function testGetWaitingTaskAndNoFreeWorker()
 {
     $worker = \Mockery::mock('Queue\\Worker');
     $worker->shouldReceive('getType')->once()->andReturn('fibonacci');
     $worker->shouldReceive('isBusy')->once()->andReturn(true);
     $task = \Mockery::mock('Queue\\Task');
     $task->shouldReceive('isWaiting')->once()->andReturn(true);
     $task->shouldReceive('getName')->once()->andReturn('fibonacci');
     $storage = \Mockery::mock('Queue\\SqlStorage');
     $storage->shouldReceive('getTasks')->once()->andReturn([$task]);
     $storage->shouldReceive('getWorkers')->once()->andReturn([$worker]);
     $manager = new Manager($storage, $task);
     list($actualTask, $actualWorker) = $manager->getWaitingTaskAndFreeWorker();
     $this->assertNull($actualTask);
     $this->assertNull($actualWorker);
 }
示例#3
0
#!/usr/bin/env php

<?php 
use PDO;
use Swift_Mailer;
use Queue\Manager;
use Swift_SmtpTransport;
use Igorw\Silex\ConfigServiceProvider;
set_time_limit(0);
require_once __DIR__ . '/vendor/autoload.php';
$app = new Silex\Application();
// For building console commands
$app->register(new Knp\Provider\ConsoleServiceProvider(), ['console.name' => 'EmailAppConsole', 'console.version' => '0.1.0', 'console.project_directory' => __DIR__ . "/.."]);
// Register general application settings
$app->register(new ConfigServiceProvider(__DIR__ . "/config/settings.json"));
// Register environment-specific parameters
$app->register(new ConfigServiceProvider(__DIR__ . "/config/{$app['environment']}.json"));
$app['swiftmailer.transport'] = Swift_SmtpTransport::newInstance($app['email_host'], $app['email_port'], $app['email_encrypt'])->setUsername($app['email_username'])->setPassword($app['email_password']);
$app['mailer'] = $app->share(function ($app) {
    return new Swift_Mailer($app['swiftmailer.transport']);
});
$app['queue_manager'] = $app->share(function ($app) {
    $dbh = new PDO($app['db_dsn'], $app['db_user'], $app['db_password']);
    $manager = new Manager();
    $manager->setPdo($dbh);
    return $manager;
});
$console = $app["console"];
$console->add(new Emailapp\EmailCommand());
$console->run();