Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Clean up php workers

  • Loading branch information...
commit 1352144ce7c22b3789d0113fb0a4d0f6c2d32d79 1 parent 89b9dba
@thousandsofthem authored
View
3  .gitignore
@@ -1,3 +1,6 @@
.idea
+
/config.ini
+*.log
+/php/code/*.zip
/IronWorker.class.php
View
6 php/Airbrake.php
@@ -6,11 +6,7 @@
$iw = new IronWorker('config.ini');
$iw->debug_enabled = true;
-$zipName = "code/$name.zip";
-
-$zipFile = IronWorker::zipDirectory(dirname(__FILE__)."/workers/airbrake", $zipName, true);
-
-$res = $iw->postCode('airbrake.php', $zipName, $name);
+$iw->upload(dirname(__FILE__)."/workers/airbrake", 'airbrake.php', $name);
$payload = array('api_key' => AIRBRAKE_API_KEY);
View
21 php/Basic.php
@@ -4,13 +4,8 @@
$name = "testBasic-php";
$iw = new IronWorker('config.ini');
-$iw->debug_enabled = true;
-$zipName = "code/$name.zip";
-$files_to_zip = array('testTask.php');
-$zipFile = IronWorker::createZip(dirname(__FILE__)."/workers/hello_world", $files_to_zip, $zipName, true);
-if (!$zipFile) die("Zip file $zipName was not created!");
-$res = $iw->postCode('testTask.php', $zipName, $name);
+$iw->upload(dirname(__FILE__)."/workers/hello_world", 'testTask.php', $name);
$payload = array(
'key_one' => 'Helpful text',
@@ -25,15 +20,13 @@
);
$task_id = $iw->postTask($name, $payload);
-echo "task_id = $task_id \n";
-sleep(10);
-$details = $iw->getTaskDetails($task_id);
+
+# Wait for task finish
+$details = $iw->waitFor($task_id);
print_r($details);
-# Check log only if task finished.
-if ($details->status != 'queued'){
- $log = $iw->getLog($task_id);
- print_r($log);
-}
+
+$log = $iw->getLog($task_id);
+echo $log;
View
7 php/BasicShedule.php
@@ -4,13 +4,8 @@
$name = "testBasic-Schedule-php";
$iw = new IronWorker('config.ini');
-$iw->debug_enabled = true;
-$zipName = "code/$name.zip";
-$files_to_zip = array('testTask.php');
-$zipFile = IronWorker::createZip(dirname(__FILE__)."/workers/hello_world", $files_to_zip, $zipName, true);
-if (!$zipFile) die("Zip file $zipName was not created!");
-$res = $iw->postCode('testTask.php', $zipName, $name);
+$iw->upload(dirname(__FILE__)."/workers/hello_world", 'testTask.php', $name);
$payload = array(
'key_one' => 'Payload',
View
14 php/BasicSimplest.php
@@ -5,20 +5,14 @@
$iw = new IronWorker('config.ini');
-# Creating zip package.
-$zipName = "code/$name.zip";
-IronWorker::zipDirectory(dirname(__FILE__)."/workers/hello_world_simple", $zipName, true);
-
-# Posting package.
-$res = $iw->postCode('testTaskSimple.php', $zipName, $name);
+# Creating and uploading code package.
+$iw->upload(dirname(__FILE__)."/workers/hello_world_simple", 'testTaskSimple.php', $name);
# Adding new task.
$task_id = $iw->postTask($name);
-echo "task_id = $task_id \n";
-
-sleep(10);
-$details = $iw->getTaskDetails($task_id);
+# Wait for task finish
+$details = $iw->waitFor($task_id);
print_r($details);
View
20 php/BatchEmailer.php
@@ -4,14 +4,8 @@
$name = "sendEmail-php";
$iw = new IronWorker('config.ini');
-$iw->debug_enabled = true;
-$zipName = "code/$name.zip";
-
-$zipFile = IronWorker::zipDirectory(dirname(__FILE__)."/workers/batch_emailer", $zipName, true);
-
-$res = $iw->postCode('sendEmail.php', $zipName, $name);
-print_r($res);
+$iw->upload(dirname(__FILE__)."/workers/batch_emailer", 'sendEmail.php', $name);
$payload = array(
'address' => "",
@@ -34,15 +28,13 @@
$task_id = $iw->postTask($name, $payload);
echo "task_id = $task_id \n";
- sleep(20);
- $details = $iw->getTaskDetails($task_id);
+
+ # Wait for task finish
+ $details = $iw->waitFor($task_id);
print_r($details);
- if ($details->status != 'queued'){
- $log = $iw->getLog($task_id);
- echo "log: \n";
- print_r($log);
- }
+ $log = $iw->getLog($task_id);
+ echo "Task log:\n $log\n";
}
View
19 php/FFmpeg.php
@@ -5,21 +5,16 @@
$iw = new IronWorker('config.ini');
-# Creating zip package.
-$zipName = "code/$name.zip";
-IronWorker::zipDirectory(dirname(__FILE__)."/workers/ffmpeg", $zipName, true);
-
-# Posting package.
-$res = $iw->postCode('ffmpeg.php', $zipName, $name);
+# Creating and uploading code package.
+$iw->upload(dirname(__FILE__)."/workers/ffmpeg", 'ffmpeg.php', $name);
# Adding new task.
$task_id = $iw->postTask($name);
-echo "task_id = $task_id \n";
-
-sleep(10);
-$details = $iw->getTaskDetails($task_id);
+# Wait for task finish
+$details = $iw->waitFor($task_id);
print_r($details);
-$log = $iw->getLog($task_id);
-print_r($log);
+# Get task log
+$log = $iw->getLog($task_id);
+echo "Task log:\n $log\n";
View
28 php/FFmpegFlv.php
@@ -5,32 +5,22 @@
$iw = new IronWorker('config.ini');
-# Creating zip package.
-$zipName = "code/$name.zip";
-IronWorker::zipDirectory(dirname(__FILE__)."/workers/ffmpeg_flv", $zipName, true);
-
-# Posting package.
-$res = $iw->postCode('ffmpeg.php', $zipName, $name);
+# Creating and uploading code package.
+$iw->upload(dirname(__FILE__)."/workers/ffmpeg_flv", 'ffmpeg.php', $name);
# Adding new task.
$payload = array(
'input_file' => 'https://s3.amazonaws.com/iron-examples/video/iron_man_2_trailer_official.flv'
);
$task_id = $iw->postTask($name, $payload);
-echo "task_id = $task_id \n";
-
# Wait for task finish
-for ($i = 0; $i < 100; $i++){
- sleep(5);
- $details = $iw->getTaskDetails($task_id);
- echo "Status: {$details->status}\n";
-
- if ($details->status != 'queued' && $details->status != 'running'){
- $log = $iw->getLog($task_id);
- print_r($log);
- break;
- }
-}
+$details = $iw->waitFor($task_id);
+echo "Status: {$details->status}\n";
+
+# Get task log
+$log = $iw->getLog($task_id);
+echo "Task log:\n $log\n";
+
View
4 php/Full.php
@@ -53,6 +53,10 @@ function tolog($name, $variable, $display = false){
$task_id = $iw->postTask($name);
tolog('post_task', $task_id, true);
+echo "\n--Wait For Task----------------------------------------\n";
+$details = $iw->waitFor($task_id);
+tolog('wait_for', $details, true);
+
echo "\n--Get Task Details------------------------------------\n";
$details = $iw->getTaskDetails($task_id);
tolog('task_details', $details, true);
View
21 php/GD_S3.php
@@ -1,5 +1,8 @@
<?php
include("../IronWorker.class.php");
+/*
+ * This example demonstrates drawing images using GD library and uploading result to Amazon S3 storage
+ */
$config = parse_ini_file('../config.ini', true);
@@ -7,13 +10,8 @@
$iw = new IronWorker('config.ini');
-# Creating zip package.
-$zipName = "code/$name.zip";
-IronWorker::zipDirectory(dirname(__FILE__)."/workers/draw_gd_and_upload_to_s3", $zipName, true);
-
-# Posting package.
-$res = $iw->postCode('gd_s3.php', $zipName, $name);
-
+# Creating and uploading code package.
+$iw->upload(dirname(__FILE__)."/workers/draw_gd_and_upload_to_s3", 'gd_s3.php', $name);
$payload = array(
's3' => array(
@@ -27,12 +25,11 @@
# Adding new task.
$task_id = $iw->postTask($name, $payload);
-echo "task_id = $task_id \n";
-sleep(10);
-
-$details = $iw->getTaskDetails($task_id);
+# Wait for task finish
+$details = $iw->waitFor($task_id);
print_r($details);
+
$log = $iw->getLog($task_id);
-print_r($log);
+echo "Task log:\n $log\n";
View
8 php/Loggly.php
@@ -4,13 +4,9 @@
$name = "loggly-php";
$iw = new IronWorker('config.ini');
-$iw->debug_enabled = true;
-$zipName = "code/$name.zip";
-
-$zipFile = IronWorker::zipDirectory(dirname(__FILE__) . "/workers/loggly", $zipName, true);
-
-$res = $iw->postCode('loggly.php', $zipName, $name);
+# Creating and uploading code package.
+$iw->upload(dirname(__FILE__)."/workers/loggly", 'loggly.php', $name);
for ($i = 1; $i <= 50; $i++)
{
View
22 php/Mongo.php
@@ -7,26 +7,22 @@
$iw = new IronWorker($config['iron_worker']);
-$zipName = "code/$name.zip";
-$files_to_zip = array('mongo.php');
-$zipFile = IronWorker::createZip(dirname(__FILE__)."/workers/mongo", $files_to_zip, $zipName, true);
-if (!$zipFile) die("Zip file $zipName was not created!");
-$res = $iw->postCode('mongo.php', $zipName, $name);
+# Creating and uploading code package.
+$iw->upload(dirname(__FILE__)."/workers/mongo", 'mongo.php', $name);
$payload = array(
'db' => $config['mongo']
);
$task_id = $iw->postTask($name, $payload);
-echo "task_id = $task_id \n";
-sleep(10);
-$details = $iw->getTaskDetails($task_id);
+
+# Wait for task finish
+$details = $iw->waitFor($task_id);
print_r($details);
-# Check log only if task finished.
-if ($details->status != 'queued'){
- $log = $iw->getLog($task_id);
- print_r($log);
-}
+
+# Check log
+$log = $iw->getLog($task_id);
+echo "Task log:\n $log\n";
View
21 php/Mysql.php
@@ -4,23 +4,16 @@
$name = "testMysql.php";
$iw = new IronWorker('config.ini');
-$iw->debug_enabled = true;
-$zipName = "code/$name.zip";
-
-$zipFile = IronWorker::zipDirectory(dirname(__FILE__)."/workers/mysql", $zipName, true);
-
-$res = $iw->postCode('testMysql.php', $zipName, $name);
-print_r($res);
+# Creating and uploading code package.
+$iw->upload(dirname(__FILE__)."/workers/mysql", 'testMysql.php', $name);
$task_id = $iw->postTask($name);
-echo "task_id = $task_id \n";
-sleep(10);
-$details = $iw->getTaskDetails($task_id);
+
+# Wait for task finish
+$details = $iw->waitFor($task_id);
print_r($details);
-if ($details->status != 'queued'){
- $log = $iw->getLog($task_id);
- print_r($log);
-}
+$log = $iw->getLog($task_id);
+echo "Task log:\n $log\n";
View
21 php/PDO.php
@@ -7,14 +7,9 @@
# Passing array of options instead of config file.
$iw = new IronWorker($config['iron_worker']);
-$iw->debug_enabled = true;
-$zipName = "code/$name.zip";
-
-$zipFile = IronWorker::zipDirectory(dirname(__FILE__)."/workers/PDO", $zipName, true);
-
-$res = $iw->postCode('Pdo.php', $zipName, $name);
-print_r($res);
+# Creating and uploading code package.
+$iw->upload(dirname(__FILE__)."/workers/PDO", 'Pdo.php', $name);
$payload = array(
'connection' => $config['pdo'],
@@ -22,13 +17,11 @@
);
$task_id = $iw->postTask($name, $payload);
-echo "task_id = $task_id \n";
-sleep(10);
-$details = $iw->getTaskDetails($task_id);
+
+# Wait for task finish
+$details = $iw->waitFor($task_id);
print_r($details);
-if ($details->status != 'queued'){
- $log = $iw->getLog($task_id);
- print_r($log);
-}
+$log = $iw->getLog($task_id);
+echo "Task log:\n $log\n";
View
8 php/PagerDuty.php
@@ -4,13 +4,9 @@
$name = "pagerDuty-php";
$iw = new IronWorker('config.ini');
-$iw->debug_enabled = true;
-$zipName = "code/$name.zip";
-
-$zipFile = IronWorker::zipDirectory(dirname(__FILE__)."/workers/pager_duty", $zipName, true);
-
-$res = $iw->postCode('pagerDuty.php', $zipName, $name);
+# Creating and uploading code package.
+$iw->upload(dirname(__FILE__)."/workers/pager_duty", 'pagerDuty.php', $name);
$payload = array(
'API_KEY' => PAGERDUTY_API_KEY
View
24 php/PharZend.php
@@ -1,25 +1,23 @@
<?php
include("../IronWorker.class.php");
-$name = "testPharZend.php";
+$name = "testPharZend-php";
$iw = new IronWorker('config.ini');
-$iw->debug_enabled = true;
-$zipName = "code/$name.zip";
-IronWorker::zipDirectory(dirname(__FILE__)."/workers/phar_zend_lib", $zipName, true);
-$res = $iw->postCode('pharZend.php', $zipName, $name);
+# Creating and uploading code package.
+$iw->upload(dirname(__FILE__)."/workers/phar_zend_lib", 'pharZend.php', $name);
$task_id = $iw->postTask($name);
-echo "task_id = $task_id \n";
-sleep(10);
-$details = $iw->getTaskDetails($task_id);
+
+# Wait for task finish
+$details = $iw->waitFor($task_id);
print_r($details);
-# Check log only if task finished.
-if ($details->status != 'queued'){
- $log = $iw->getLog($task_id);
- print_r($log);
-}
+
+# Check log
+$log = $iw->getLog($task_id);
+echo "Task log:\n $log\n";
+
View
19 php/Redis.php
@@ -4,21 +4,16 @@
$name = "testRedis-PHP";
$iw = new IronWorker('config.ini');
-$iw->debug_enabled = true;
-$zipName = "code/$name.zip";
+# Creating and uploading code package.
+$iw->upload(dirname(__FILE__)."/workers/php_redis", 'testRedis.php', $name);
-$zipFile = IronWorker::zipDirectory(dirname(__FILE__)."/workers/php_redis", $zipName, true);
-
-$res = $iw->postCode('testRedis.php', $zipName, $name);
$task_id = $iw->postTask($name);
-echo "task_id = $task_id \n";
-sleep(10);
-$details = $iw->getTaskDetails($task_id);
+
+# Wait for task finish
+$details = $iw->waitFor($task_id);
print_r($details);
-if ($details->status != 'queued'){
- $log = $iw->getLog($task_id);
- print_r($log);
-}
+$log = $iw->getLog($task_id);
+echo "Task log:\n $log\n";
View
21 php/Twitter.php
@@ -4,28 +4,21 @@
$name = "postToTwitter-php";
$iw = new IronWorker('config.ini');
-$iw->debug_enabled = true;
-$zipName = "code/$name.zip";
-
-$zipFile = IronWorker::zipDirectory(dirname(__FILE__)."/workers/post_to_twitter", $zipName, true);
-
-$res = $iw->postCode('postToTwitter.php', $zipName, $name);
+# Creating and uploading code package.
+$iw->upload(dirname(__FILE__)."/workers/post_to_twitter", 'postToTwitter.php', $name);
$payload = array(
'message' => "Hello From PHPWorker at ".date('r')."!\n",
'url' => 'http://www.iron.io/'
);
-
$task_id = $iw->postTask($name, $payload);
-echo "task_id = $task_id \n";
-sleep(15);
-$details = $iw->getTaskDetails($task_id);
+
+# Wait for task finish
+$details = $iw->waitFor($task_id);
print_r($details);
-if ($details->status != 'queued'){
- $log = $iw->getLog($task_id);
- print_r($log);
-}
+$log = $iw->getLog($task_id);
+echo "Task log:\n $log\n";
Please sign in to comment.
Something went wrong with that request. Please try again.