public function fire()
 {
     $worker_name = $this->option('worker_name');
     $worker_file_name = $this->option('exec_worker_file_name');
     $token = Config::get('queue.connections.iron.token', 'xxx');
     $project_id = Config::get('queue.connections.iron.project', 'xxx');
     $worker = new \IronWorker(array('token' => $token, 'project_id' => $project_id));
     $this->info("Starting to upload \"{$worker_name}\" worker" . PHP_EOL);
     @$worker->upload(getcwd(), "workers/" . $worker_file_name, $worker_name, array("stack" => 'php-5.4'));
 }
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";
}
예제 #3
0
파일: EYiiron.php 프로젝트: br0sk/yiiron
 /**
  * Set a Task’s Progress. Work only inside a worker
  *
  * Example (inside a worker):
  * <code>
  * require_once "phar://iron_worker.phar";
  * $worker = new IronWorker(); # assuming you have iron.json inside a worker
  * $worker->setCurrentTaskProgress(50, "Task is half-done");
  * </code>
  * @param int $percent An integer, between 0 and 100 inclusive, that describes the completion of the task.
  * @param string $msg Any message or data describing the completion of the task. Must be a string value, and the 64KB request limit applies.
  * @return mixed
  * @throws CException
  */
 public function workerSetCurrentTaskProgress($percent, $msg = '')
 {
     try {
         return $this->_worker->setCurrentTaskProgress($percent, $msg);
     } catch (Exception $e) {
         Yii::log('Error in IronWorker: ' . $e->getMessage(), 'error', 'ext.yiiron');
         throw new CException($e->getMessage());
     }
 }
예제 #4
0
function queue_worker($iw, $name)
{
    ob_start();
    $tmpdir = $_SERVER['TMP_DIR'];
    if (empty($tmpdir)) {
        $tmpdir = dirname(__FILE__);
    }
    $zipName = $tmpdir . "/{$name}.zip";
    $file = IronWorker::zipDirectory(dirname(__FILE__) . "/../workers", $zipName, true);
    $res = $iw->postCode('sampleWorker.php', $zipName, $name);
    $payload = array('sample param' => "sample value");
    $task_id = $iw->postTask($name, $payload);
    ob_end_clean();
}
function queue_worker($iw, $name, $num_emails)
{
    ob_start();
    $tmpdir = $_SERVER['TMP_DIR'];
    if (empty($tmpdir)) {
        $tmpdir = dirname(__FILE__);
    }
    $zipName = $tmpdir . "/{$name}.zip";
    $file = IronWorker::zipDirectory(dirname(__FILE__) . "/../workers", $zipName, true);
    $res = $iw->postCode('emailWorker.php', $zipName, $name);
    $tasks = array();
    for ($i = 1; $i <= $num_emails / 10; $i++) {
        $payload = array('num_emails' => 10);
        $task_id = $iw->postTask($name, $payload);
    }
    do {
        $details = $iw->getTaskDetails($task_id);
        #waiting for a last task
        $queued_or_running = array("running", "queued");
    } while (in_array($details->status, $queued_or_running));
    ob_end_clean();
}
예제 #6
0
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker();
$worker->upload("worker/", 'sendEmail.php', "sendEmail-php");
예제 #7
0
<?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";
예제 #9
0
 function testZipUploading()
 {
     IronWorker::createZip($this->workerDir(), array('worker.php'), '_worker.zip', true);
     $res = $this->worker->postCode('worker.php', '_worker.zip', 'TestWorker');
     $this->assertEqual($res->status_code, '200');
 }
예제 #10
0
<?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";
예제 #11
0
<?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);
}
예제 #12
0
<?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";
예제 #13
0
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker();
$worker->upload("worker/", 'Pdo.php', "PDO");
예제 #14
0
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker();
$worker->debug_enabled = true;
$payload = array('key_one' => 'Payload', 'key_two' => 2);
# 3 minutes later
$start_at = time() + 3 * 60;
# Run task every 2 minutes 10 times
$schedule_id = $worker->postScheduleAdvanced("Scheduling", $payload, $start_at, 2 * 60, null, 10);
# Get schedule information
$schedule = $worker->getSchedule($schedule_id);
print_r($schedule);
예제 #15
0
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker();
$worker->upload("worker/", 'testMysql.php', "MySQL");
예제 #16
0
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker();
$worker->debug_enabled = true;
$worker->upload("worker/", 'airbrake.php', "AirBrake");
예제 #17
0
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker();
# Creating and uploading code package.
$worker->upload("worker/", 'gd_s3.php', "testGD_S3");
예제 #18
0
<?php

require_once "phar://iron_worker.phar";
$worker = new IronWorker();
$name = "emailWorker.php";
//uploading worker
$worker->upload(dirname(__FILE__) . "/workers/email_worker", 'emailWorker.php', $name);
$payload = array('host' => 'smtp.gmail.com', 'port' => 587, 'username' => 'username', 'password' => 'passw', 'from' => '*****@*****.**', 'to' => '*****@*****.**', 'subject' => "Title", 'body' => "Hey it's a body");
//queueing task
$task_id = $worker->postTask($name, $payload);
예제 #19
0
 /**
  * Run this action like this: yiic myAction uploadIronWorker
  *
  * This command can be integrated to your deployment system. When you have committed your code you can
  * run this command to deploy the code to the iron.io servers.
  *
  * This command zips all the code needed to be uploaded to the Iron Workers
  * Upload the zipped file to Iron Workers. This will create a new version of the code for the current project
  *
  * It will also create a task in the iron.io hud named after the command file. All the actions in this command file
  * will run  as this task on iron.io.
  *
  * It prepares all the files in the runtoime directory and cleans up when finished.
  * TODO: Test in Windows environment
  */
 public function actionUploadIronWorker()
 {
     /**
      * The EYiiron class instance. It is our gateway to all iron.io services
      * @var EYiiron $yiiron
      */
     $yiiron = Yii::app()->yiiron;
     //This is where we store the files before deploying them on iron.io
     $tmpDir = Yii::app()->getRuntimePath() . DIRECTORY_SEPARATOR . 'ironworkers' . DIRECTORY_SEPARATOR;
     echo "Using PHP Stack :" . $yiiron->stack . "\n";
     //Clean up in the directory. We do this before we start in case the old code was not fully removed.
     EIronWorkersCommand::deleteDir($tmpDir);
     //Make sure we have a clean environment before preparing the runtime environment for iron.io.
     //THis is crucial so we know that the code we deploy is exactly the same as we run locally.
     if (!file_exists($tmpDir)) {
         echo $tmpDir . " doesn't exist creating it now...\n";
         if (!mkdir($tmpDir)) {
             echo "**Error**: Creation failed. Please check your permissions!\n";
             exit(0);
         }
     } else {
         echo "**Error**: " . $tmpDir . " existed even though we tried to fully remove it.\n" . "It could be a permission problem please remove " . $tmpDir . " manually before running this command again.\n";
         exit(0);
     }
     echo "Copying Yii Framework to tmp dir...\n";
     /**
      * The Framework path
      * @var string $yiiPath
      */
     $yiiPath = Yii::getFrameworkPath() . "/../";
     /**
      * The path of your Yii app. Usually the protected folder
      * @var string $appPath
      */
     $appPath = Yii::app()->getBasePath() . "/";
     echo "Yii path: " . $yiiPath . "\n";
     CFileHelper::copyDirectory($yiiPath, $tmpDir . 'yii');
     echo "Copying app from " . $appPath . " to the tmp dir " . $tmpDir . 'app/' . basename($appPath) . "\n";
     //Exclude as much as we can to get a slim file to upload
     CFileHelper::copyDirectory($appPath, $tmpDir . 'app/' . basename($appPath), Yii::app()->yiiron->workerFileCopyOptions);
     echo "Zipping code to " . $tmpDir . "iron_worker.zip\n";
     IronWorker::zipDirectory($tmpDir, $tmpDir . 'iron_worker.zip', true);
     echo "Uploading the code for the worker " . $this->name . "...\n";
     //This is so we can handle custom extension paths
     $ironWorkerExtensionPath = str_replace($appPath, "app/" . basename($appPath) . "/", Yii::app()->getExtensionPath());
     //Read the config array into an array
     $configFile = json_encode(require $appPath . $yiiron->configFile);
     //Posting the code and the initial php file to execute. This on the Iron Worker platform, not locally
     $res = $yiiron->workerPostCode($ironWorkerExtensionPath . "/yiiron/yiic-yiiron.php", $tmpDir . 'iron_worker.zip', $this->getName(), array('config' => $configFile, 'stack' => $yiiron->stack));
     echo "Finished uploading iron_worker.zip (" . EIronWorkersCommand::format_bytes(filesize($tmpDir . 'iron_worker.zip')) . ")\n";
     //Remove all files
     echo "Remove all temp files...\n";
     //EIronWorkersCommand::deleteDir($tmpDir);
     echo "Done!\n";
     echo "Find the worker here http://hud.iron.io/tq/projects/" . Yii::app()->yiiron->projectId . "/tasks/" . $res->id . "/activity\n";
     echo "Now run your command like this: './yiic " . $this->name . " myAction --ironWorker=true' to execute it as an Iron Worker.\n";
 }
예제 #20
0
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker();
$worker->debug_enabled = true;
$worker->postTask("Redis");
예제 #21
0
<?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";
예제 #22
0
<?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";
}
예제 #23
0
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker();
echo "Uploading 'hello_worker.php' to Iron.io as worker named 'HelloWorker' ... stay tuned ...\n";
$worker->upload(dirname(__FILE__), 'hello_worker.php', 'HelloWorker');
echo "... and the upload is finished, now run `php enqueue.php` to run it on Iron.io\n";
예제 #24
0
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker();
$worker->debug_enabled = true;
$worker->postTask("pharZend");
 public function testZipUploading()
 {
     IronWorker::createZip($this->workerDir(), array('worker.php'), '_worker.zip', true);
     $res = $this->worker->postCode('worker.php', '_worker.zip', 'TestWorker');
     $this->assertEqual($res->msg, 'Upload successful.');
 }
예제 #26
0
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker('config.ini');
$worker->upload(dirname(__FILE__) . "/workers/master", 'master_worker.php', 'MasterWorker');
$worker->upload(dirname(__FILE__) . "/workers/slave", 'slave_worker.php', 'SlaveWorker');
예제 #27
0
<?php

ob_start();
include __DIR__ . '/../lib/IronWorkerWrapper.php';
$config = parse_ini_file(__DIR__ . '/../config.ini', true);
$url = $_REQUEST['url'];
$queue_name = $_REQUEST['queue_name'];
$name = "imageWorker.php";
$tmpdir = $_SERVER['TMP_DIR'];
if (empty($tmpdir)) {
    $tmpdir = dirname(__FILE__);
}
print_r($tmpdir);
$zipName = $tmpdir . "/{$name}.zip";
$file = IronWorker::zipDirectory(dirname(__FILE__) . "/../workers", $zipName, true);
$res = $iw->postCode('imageWorker.php', $zipName, $name);
print_r($res);
$payload = array('iron_mq' => array('token' => $config['iron_mq']['token'], 'project_id' => $config['iron_mq']['project_id']), 'image_url' => $url, 'queue_name' => $queue_name);
$task_id = $iw->postTask($name, $payload);
ob_end_clean();
echo $task_id;
예제 #28
0
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker();
$worker->upload("worker/", 'worker.php', "Scheduling");
예제 #29
0
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker();
$params = array('stack' => 'ffmpeg-2.3');
$worker->upload("worker/", 'ffmpeg.php', "FFmpeg-Flv", $params);
예제 #30
0
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker();
$worker->upload("worker/", 'ffmpeg.php', "FFmpeg-Flv");