public function startWorkers($numToStart)
 {
     $vadmin = Config::get('base_path') . 'vadmin';
     for ($i = 0; $i < $numToStart; $i++) {
         $this->workers[] = new Process(sprintf("php -f %s virge:graphite:worker %s", $vadmin, $this->queueName));
     }
 }
Beispiel #2
0
 /**
  * Create the migration
  * @param string $table
  * @return string|boolean
  */
 public function createMigration($table)
 {
     $filename = str_replace(' ', '_', $table) . date('Y-m-d-H-i-s') . '.php';
     $file = Config::get('app_path') . 'db/' . $filename;
     $result = file_put_contents($file, file_get_contents(Config::path("Virge\\Database@resources/stubs/install.php")));
     return $result ? $file : false;
 }
Beispiel #3
0
 protected static function getService()
 {
     //TODO: caching
     $config = Config::get('database');
     $serviceName = $config['service'];
     return Virge::service($serviceName);
 }
 /**
  * Include a component
  * @param string $template
  * @param array $parameters
  */
 public function component($template, $parameters = array())
 {
     foreach ($parameters as $name => $value) {
         ${$name} = $value;
     }
     include Config::path($template);
 }
 /**
  * Remove anything that is older than 15 minutes, we only want to keep 15 
  * minutes worth of history
  */
 public function cleanup()
 {
     $config = Config::get('cron');
     $minutes = isset($config['save_time']) ? $config['save_time'] : 15;
     $startDate = new \DateTime();
     $startDate->modify("-{$minutes} minutes");
     $sql = "DELETE FROM `virge_cron_job` WHERE `finished_on` <= ?";
     Database::query($sql, $startDate);
 }
Beispiel #6
0
 protected function getConfigDirectory($directory)
 {
     $possible = ['/', '/resources/', Config::get('app', 'resource_dir')];
     foreach ($possible as $prefix) {
         if (is_dir($directory . $prefix . 'config/')) {
             break;
         }
     }
     return $directory . $prefix . 'config/';
 }
 /**
  * @return AMQPStreamConnection
  */
 protected function getConnection()
 {
     if (isset($this->connection)) {
         return $this->connection;
     }
     $host = Config::get('queue', 'host');
     $port = Config::get('queue', 'port');
     $user = Config::get('queue', 'user');
     $pass = COnfig::get('queue', 'pass');
     return $this->connection = new AMQPStreamConnection($host, $port, $user, $pass);
 }
 /**
  * Remove anything that is older than 15 minutes, we only want to keep 15 
  * minutes worth of history
  */
 public function start()
 {
     if ($this->instanceAlreadyRunning()) {
         return $this->terminate();
     }
     $this->path = Config::get('base_path');
     $this->command = WorkerCommand::COMMAND;
     if (!$this->getJobService()->hasJobs()) {
         $this->getScheduleService()->scheduleJobs();
     }
     $this->startJobs();
 }
Beispiel #9
0
 /**
  * 
  * @param string $name
  */
 public function createConnection($name)
 {
     //TODO: determine connection type etc
     $connection = new Mysql();
     $config = Config::get('database');
     $connectionsConfig = $config['connections'];
     if (!isset($connectionsConfig[$name])) {
         throw new \InvalidArgumentException(sprintf("Invalid connection %s was not defined", $name));
     }
     //TODO: defaults
     $connectionConfig = $connectionsConfig[$name];
     $connection->setName($name);
     $connection->setHostname($connectionConfig['hostname']);
     $connection->setUsername($connectionConfig['username']);
     $connection->setPassword($connectionConfig['password']);
     $connection->setDatabase($connectionConfig['database']);
     //set additional parameters
     if (!$connection->connect()) {
         throw new ConnectionException(sprintf("Failed to connect to %s, error: %s", $name, $connection->getError()));
     }
     return $connection;
 }
Beispiel #10
0
 /**
  * Do a job
  * @param int $jobId
  * @throws \InvalidArgumentException
  */
 public function work($jobId)
 {
     $job = new Job();
     if (!$job->load($jobId)) {
         throw new \InvalidArgumentException(sprintf("No job found for Job ID: %s", $jobId));
     }
     $job->setStartedOn(new \DateTime());
     $job->setStartedBy(get_current_user());
     $job->save();
     $this->path = Config::get('base_path');
     $arguments = $job->getArguments();
     $argumentString = implode(" ", array_map(function ($argument) {
         return "\"{$argument}\"";
     }, $arguments));
     $command = new Process("php -f {$this->path}vadmin.php {$job->getCallable()} {$argumentString}");
     while (!$command->isFinished()) {
         sleep(1);
     }
     $job->setFinishedOn(new \DateTime());
     $job->setSummary($command->getOutput());
     $job->save();
 }
 /**
  * 
  * @param string $filepath
  * @return Response
  */
 public function render($filepath, $parameters = array())
 {
     return $this->getTemplatingService()->render(Config::path($filepath), $parameters);
 }
Beispiel #12
0
 /**
  * Setup table to hold our migrations
  */
 public function init()
 {
     include_once Config::path("Virge\\Cron@resources/setup/database.php");
     Cli::output('Successfully initialized cron table');
 }
Beispiel #13
0
<?php

use Virge\Core\Config;
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);
/**
 * 
 * @author Michael Kramer
 */
chdir(dirname(__FILE__));
require_once 'bootstrap.php';
// Create new Notifier instance.
global $_airbrakeNotifier;
$config = Config::get('app');
if ($config['environment'] === 'production') {
    $_airbrakeNotifier = new \Airbrake\Notifier(array('projectId' => 115002, 'projectKey' => '9280f8dc5b80d03f9a11e56d773dc755'));
    // Set global notifier instance.
    \Airbrake\Instance::set($_airbrakeNotifier);
    // Register error and exception handlers.
    $handler = new \Airbrake\ErrorHandler($_airbrakeNotifier);
    $handler->register();
}
//handle arguments
$args = array();
if (isset($argv[2])) {
    for ($i = 2; $i <= $argc; $i++) {
        $args[] = isset($argv[$i]) ? $argv[$i] : NULL;
    }
}
$command = isset($argv[1]) ? $argv[1] : null;
$reactor = new Reactor();
$reactor->run('prod', 'cli', 'execute', array($command, $args));
Beispiel #14
0
 /**
  * Quick hashing algorithm
  * @param string $string
  * @param string $salt
  * @param string $encryptionAlgorithm
  * @param string $key
  * @return string
  */
 public static function hash($string = '', $salt = '', $encryptionAlgorithm = false, $key = false)
 {
     if (!$encryptionAlgorithm) {
         $encryptionAlgorithm = Config::get('app', 'encryption_algorithm');
     }
     if (!$key) {
         $key = Config::get('app', 'encryption_key');
     }
     if (strlen($string) === '') {
         $string = md5(microtime());
     }
     $string .= $salt;
     return hash_hmac($encryptionAlgorithm, $string, $key);
 }
 public function init()
 {
     require_once Config::path("\\Virge\\Event@setup/events.php");
 }