Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added max_concurrency, retries, retries_delay to code uploading; vers…

…ion dump; regenerate .phar; tests for new functionality
  • Loading branch information...
commit 7375db334881a0acc097c2bf3ceeb2622c72ec6e 1 parent b9f802b
@thousandsofthem thousandsofthem authored
View
19 IronWorker.class.php
@@ -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.3.2
+ * @version 1.3.3
* @package IronWorkerPHP
* @copyright Feel free to copy, steal, take credit for, or whatever you feel like doing with this code. ;)
*/
@@ -23,7 +23,7 @@ class IronWorker_Exception extends Exception{
*/
class IronWorker extends IronCore{
- protected $client_version = '1.3.2';
+ protected $client_version = '1.3.3';
protected $client_name = 'iron_worker_php';
protected $product_name = 'iron_worker';
protected $default_values = array(
@@ -70,17 +70,21 @@ function __construct($config_file_or_options = null){
* @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
+ * @param array $options Optional parameters:
+ * - "max_concurrency" The maximum number of tasks that should be run in parallel.
+ * - "retries" The number of auto-retries of failed task.
+ * - "retries_delay" Delay in seconds between retries.
* @return bool Result of operation
* @throws Exception
*/
- public function upload($directory, $run_filename, $code_name){
+ public function upload($directory, $run_filename, $code_name, $options = array()){
$temp_file = tempnam(sys_get_temp_dir(), 'iron_worker_php');
if (!self::zipDirectory($directory, $temp_file, true)){
unlink($temp_file);
return false;
}
try{
- $this->postCode($run_filename, $temp_file, $code_name);
+ $this->postCode($run_filename, $temp_file, $code_name, $options);
}catch(Exception $e){
unlink($temp_file);
throw $e;
@@ -218,9 +222,13 @@ public function getCodeDetails($code_id){
* @param string $filename This file will be launched as worker
* @param string $zipFilename zip file containing code to execute
* @param string $name referenceable (unique) name for your worker
+ * @param array $options Optional parameters:
+ * - "max_concurrency" The maximum number of tasks that should be run in parallel.
+ * - "retries" The number of auto-retries of failed task.
+ * - "retries_delay" Delay in seconds between retries.
* @return mixed
*/
- public function postCode($filename, $zipFilename, $name){
+ public function postCode($filename, $zipFilename, $name, $options = array()){
// Add IronWorker functions to the uploaded worker
$this->addRunnerToArchive($zipFilename, $filename);
@@ -241,6 +249,7 @@ public function postCode($filename, $zipFilename, $name){
"options" => array(),
"access_key" => $name
);
+ $sendingData = array_merge($sendingData, $options);
$url = "projects/{$this->project_id}/codes";
$post = array(
"data" => json_encode($sendingData),
View
BIN  iron_worker.phar
Binary file not shown
View
1  test/test_queuing.php
@@ -5,6 +5,7 @@ class TestQueueing extends IronUnitTestCase {
function setUp() {
parent::setUp();
$this->worker = new IronWorker('_config.json');
+ $this->worker->ssl_verifypeer = false;
$this->worker->upload($this->workerDir(), 'worker.php', 'TestWorker');
}
View
1  test/test_scheduling.php
@@ -4,6 +4,7 @@ class TestScheduling extends IronUnitTestCase {
function setUp() {
parent::setUp();
$this->worker = new IronWorker('_config.json');
+ $this->worker->ssl_verifypeer = false;
$this->worker->upload($this->workerDir(), 'worker.php', 'TestWorker');
}
View
24 test/test_uploading.php
@@ -5,6 +5,7 @@ class TestUploading extends IronUnitTestCase {
function setUp() {
parent::setUp();
$this->worker = new IronWorker('_config.json');
+ $this->worker->ssl_verifypeer = false;
}
function tearDown() {
@@ -36,6 +37,29 @@ function testGetCodesList(){
$this->assertTrue(strlen($codes[0]->id) > 0);
}
+
+ function testUploadingWithOptions(){
+ $options = array(
+ 'max_concurrency' => 10,
+ 'retries' => 5,
+ 'retries_delay' => 20
+ );
+ $this->assertTrue($this->worker->upload($this->workerDir(), 'worker.php', 'TestWorkerOptions', $options));
+
+ $codes = $this->worker->getCodes();
+
+ $is_worker_present = false;
+ foreach($codes as $code){
+ if ($code->name == 'TestWorkerOptions'){
+ $this->assertEqual($code->max_concurrency, 10);
+ $this->assertEqual($code->retries, 5);
+ $this->assertEqual($code->retries_delay, 20);
+ $is_worker_present = true;
+ }
+ }
+ $this->assertTrue($is_worker_present);
+ }
+
function testGetCodeDetails(){
$codes = $this->worker->getCodes();
$details = $this->worker->getCodeDetails($codes[0]->id);
Please sign in to comment.
Something went wrong with that request. Please try again.