Ejemplo n.º 1
0
// <?php
// $context = T24\Context\ExecutionContext::create();
// $context['container'] = $app->getContainer();
// $context->setEventDispatcher($app->getContainer()->get['event_dispatcher']);
// require('run-agent.php');
//
$context = isset($context) ? $context : ExecutionContext::create();
if (!$context instanceof ExecutionContext) {
    throw new RuntimeException('Execution context is not an instance of T24\\Handler\\ExecutionContext but ' . get_class($context));
}
// php file.php ./assets/example.txt
ini_set('display_errors', 1);
$cmd = new Commando\Command();
$cmd->setHelp('sqs agent')->option('ttl')->describedAs('sets the ttl / runtime of the script. Defaults to 45 (in seconds)')->option('sleep')->defaultsTo(null)->describedAs('sets the time to rest between two message retrievals. Defaults to 3 (in seconds)')->option('config')->defaultsTo(null)->describedAs('configuration file');
$run = function () use($cmd, $context) {
    $_options = $cmd->getOptions();
    $options = [];
    foreach ($_options as $key => $option) {
        $options[$key] = $option->getValue();
    }
    $options['base_dir'] = __DIR__ . '/../';
    // for this binary, subscribe to some configuration events to load config files etc.
    // first, load the configuration file
    $context->getEventDispatcher()->addListener(SqsEvents::EVENT_SQSAGENT_CONFIGURE, function (ConfigEvent $event) use($options) {
        if ($options['config']) {
            $newCfg = json_decode(file_get_contents($options['config']), true);
            if (!$newCfg) {
                throw new RuntimeException('could not load config file ' . $options['config']);
            }
            $event->getConfig()->merge($newCfg);
        }