Exemple #1
0
 /**
  * Queues already uploaded worker
  *
  * @param string $name Package name
  * @param array $payload Payload for task
  * @param array $options Optional parameters:
  *  - "priority" priority queue to run the job in (0, 1, 2). 0 is default.
  *  - "timeout" maximum runtime of your task in seconds. Maximum time is 3600 seconds (60 minutes). Default is 3600 seconds (60 minutes).
  *  - "delay" delay before actually queueing the task in seconds. Default is 0 seconds.
  * @return string Created Task ID
  * @throws CException
  */
 public function workerPostTask($name, $payload = array(), $options = array())
 {
     try {
         return $this->_worker->postTask($name, $payload, $options);
     } catch (Exception $e) {
         Yii::log('Error in IronWorker: ' . $e->getMessage(), 'error', 'ext.yiiron');
         throw new CException($e->getMessage());
     }
 }
function queue_worker($payload, $emails)
{
    $name = "emailWorker.php";
    $iw = new IronWorker(array('token' => $payload->token, 'project_id' => $payload->project_id));
    $payload = array('host' => $payload->host, 'port' => $payload->port, 'username' => $payload->username, 'password' => $payload->username, 'from' => $payload->from, 'to' => $emails, 'subject' => "Welcome emails", 'body' => "Hey it's a body", 'token' => $payload->token, 'project_id' => $payload->project_id);
    $task_id = $iw->postTask($name, $payload);
    echo "task_id = {$task_id} \n";
    # Wait for task finish
    $details = $iw->waitFor($task_id);
    print_r($details);
    $log = $iw->getLog($task_id);
    echo "Task log:\n {$log}\n";
}
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker();
$worker->debug_enabled = true;
$worker->postTask("pharZend");
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker();
$payload = array('address' => "", 'name' => "Dear Friend", 'subject' => 'PHPMailer Test Subject via mail(), basic', 'reply_to' => array('address' => "*****@*****.**", 'name' => "First Last"), 'from' => array('address' => "*****@*****.**", 'name' => "First Last"));
# Send 5 different mails
for ($i = 1; $i <= 5; $i++) {
    $payload['address'] = "name_{$i}@example.com";
    $payload['name'] = "Dear Friend {$i}";
    $task_id = $worker->postTask("sendEmail-php", $payload);
    echo "task_id = {$task_id} \n";
    # Wait for task finish
    $details = $worker->waitFor($task_id);
    print_r($details);
    $log = $worker->getLog($task_id);
    echo "Task log:\n {$log}\n";
}
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker();
$worker->debug_enabled = true;
$worker->postTask("Redis");
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker();
$config = parse_ini_file('config.ini', true);
$task_id = $worker->postTask('Mongo', array('db' => $config['mongo']));
# Wait for task finish
$details = $worker->waitFor($task_id);
print_r($details);
# Check log
$log = $worker->getLog($task_id);
echo "Task log:\n {$log}\n";
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker();
$worker->debug_enabled = true;
$payload = array('message' => "Hello From PHPWorker at " . date('r') . "!\n", 'url' => 'http://www.iron.io/');
$task_id = $worker->postTask("Twitter", $payload);
# Wait for task finish
$details = $worker->waitFor($task_id);
print_r($details);
$log = $worker->getLog($task_id);
echo "Task log:\n {$log}\n";
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker();
$worker->debug_enabled = true;
$payload = array('query' => "iron.io");
$task_id = $worker->postTask("PHPWorker101", $payload);
# Wait for task finish
$details = $worker->waitFor($task_id);
print_r($details);
$log = $worker->getLog($task_id);
echo "Task log:\n {$log}\n";
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker();
$worker->debug_enabled = true;
$task_id = $worker->postTask("MySQL");
# Wait for task finish
$details = $worker->waitFor($task_id);
print_r($details);
$log = $worker->getLog($task_id);
echo "Task log:\n {$log}\n";
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker();
$worker->debug_enabled = true;
$task_id = $worker->postTask("FFmpeg-Frames");
# Wait for task finish
$details = $worker->waitFor($task_id);
print_r($details);
$log = $worker->getLog($task_id);
echo "Task log:\n {$log}\n";
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker();
$worker->debug_enabled = true;
$payload = array('input_file' => 'https://s3.amazonaws.com/iron-examples/video/iron_man_2_trailer_official.flv');
$task_id = $worker->postTask("FFmpeg-Flv", $payload);
# Wait for task finish
$details = $worker->waitFor($task_id);
print_r($details);
$log = $worker->getLog($task_id);
echo "Task log:\n {$log}\n";
<?php

require_once "phar://../iron_worker.phar";
/*
 * This example demonstrates drawing images using GD library and uploading result to Amazon S3 storage
 */
$worker = new IronWorker();
$config = parse_ini_file('../config.ini', true);
$payload = array('s3' => array('access_key' => $config['s3']['access_key'], 'secret_key' => $config['s3']['secret_key'], 'bucket' => $config['s3']['bucket']), 'image_url' => 'http://www.iron.io/assets/banner-mq-bg.jpg', 'text' => 'Hello from Iron Worker!');
# Adding new task.
$task_id = $worker->postTask("testGD_S3", $payload);
# Wait for task finish
$details = $worker->waitFor($task_id);
print_r($details);
$log = $worker->getLog($task_id);
echo "Task log:\n {$log}\n";
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker();
echo "Starting a task for 'HelloWorker' on Iron.io ... stay tuned ...\n";
$task_id = $worker->postTask('HelloWorker', array('some_param' => 'some_value', 'other_param' => array(1, 2, 3)));
echo "Your task #{$task_id} has been queued up, check https://hud.iron.io to see your task status and log.\n";
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker();
$worker->debug_enabled = true;
$payload = array('api_key' => AIRBRAKE_API_KEY);
$worker->postTask("AirBrake", $payload);
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker();
$worker->debug_enabled = true;
# launch 50 workers
for ($i = 1; $i <= 50; $i++) {
    $payload = array('api_key' => LOGGLY_KEY, 'i' => $i);
    $worker->postTask('Loggly', $payload);
}
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker('config.ini');
$name = 'MasterWorker';
$data = @parse_ini_file('config.ini', true);
$payload = array('token' => $data['iron_worker']['token'], 'project_id' => $data['iron_worker']['project_id']);
$task_id = $worker->postTask($name, $payload);
echo "Your task #{$task_id} has been queued up, check https://hud.iron.io to see your task status and log. \n";
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker();
$worker->debug_enabled = true;
$payload = array('API_KEY' => PAGERDUTY_API_KEY);
$worker->postTask("PagerDuty", $payload);
<?php

include "./lib/iron_worker.phar";
echo "This is master worker\n Trying to run slave...\n";
$payload = getPayload();
print_r($payload);
$name = "SlaveWorker";
$iw = new IronWorker(array('token' => $payload->token, 'project_id' => $payload->project_id));
$payload = array('token' => $payload->token, 'project_id' => $payload->project_id);
$task_id = $iw->postTask($name, $payload);
echo "task_id = {$task_id} \n";
# Wait for task finish
$details = $iw->waitFor($task_id);
print_r($details);
$log = $iw->getLog($task_id);
echo "Task log:\n {$log}\n";
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker();
$worker->debug_enabled = true;
$config = parse_ini_file('../config.ini', true);
$payload = array('connection' => $config['pdo'], 'yet_another_value' => array('value', 'value #2'));
$task_id = $worker->postTask("PDO", $payload);
# Wait for task finish
$details = $worker->waitFor($task_id);
print_r($details);
$log = $worker->getLog($task_id);
echo "Task log:\n {$log}\n";