Permalink
Browse files

New upload() method

  • Loading branch information...
1 parent 8a3c5b3 commit aa2991ef700a3c2729ac59b55635dd7fe0aa607f @thousandsofthem thousandsofthem committed Apr 15, 2012
Showing with 41 additions and 2 deletions.
  1. +28 −1 IronWorker.class.php
  2. +13 −1 README.md
View
@@ -6,7 +6,7 @@
* @link https://github.com/iron-io/iron_worker_php
* @link http://www.iron.io/
* @link http://dev.iron.io/
- * @version 1.1.2
+ * @version 1.1.3
* @package IronWorkerPHP
* @copyright Feel free to copy, steal, take credit for, or whatever you feel like doing with this code. ;)
*/
@@ -129,6 +129,33 @@ function __construct($config_file_or_options){
$this->project_id = $project_id;
}
+ /**
+ * Zips and uploads your code
+ *
+ * Shortcut for zipDirectory() + postCode()
+ *
+ * @param string $directory Directory with worker files
+ * @param string $run_filename This file will be launched as worker
+ * @param string $code_name Referenceable (unique) name for your worker
+ * @return bool Result of operation
+ * @throws Exception
+ */
+ public function upload($directory, $run_filename, $code_name){
+ $temp_file = tempnam(sys_get_temp_dir(), 'iron_worker_php');
+ if (!self::zipDirectory($directory, $temp_file, true)){
+ unlink($temp_file);
+ return false;
+ }
+ try{
+ $response = $this->postCode($run_filename, $temp_file, $code_name);
+ $is_ok = ($response->status_code == 200);
+ }catch(Exception $e){
+ unlink($temp_file);
+ throw $e;
+ }
+ return $is_ok;
+ }
+
/**
* Creates a zip archieve from array of file names
*
View
@@ -48,6 +48,18 @@ echo "Hello PHP World!\n";
```
## Upload code to server
+You can upload worker in one step:
+
+```php
+<?php
+# 1. Directory where worker files lies
+# 2. This file will be launched as worker
+# 3. Referenceable (unique) name for your worker
+$iw->upload(dirname(__FILE__)."/hello_world/", 'HelloWorld.php', 'HelloWorld');
+
+```
+OR zip and upload separately:
+
* Zip worker:
```php
@@ -64,7 +76,7 @@ IronWorker::zipDirectory(dirname(__FILE__)."/hello_world/", 'worker.zip', true);
<?php
$res = $iw->postCode('HelloWorld.php', 'worker.zip', 'HelloWorld');
```
-Where 'HelloWorld' is a worker name which should be used later for queueing and sheduling.
+Where 'HelloWorld' is a worker name which should be used later for queueing and scheduling.
## Worker examples

0 comments on commit aa2991e

Please sign in to comment.