示例#1
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();
}
示例#3
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;
示例#4
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";
 }