Skip to content

Commit

Permalink
New api call getSchedule(). Humanized package names for examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
thousandsofthem committed Jan 10, 2012
1 parent 3234667 commit c25744e
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 26 deletions.
52 changes: 40 additions & 12 deletions IronWorker.class.php
Expand Up @@ -199,8 +199,9 @@ public function getCodeDetails($code_id, $project_id = ''){

/**
* Uploads your code package
* @param string $project_id
* @param string $filename this file will be launched as worker
*
* @param string $project_id Project ID or empty string
* @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
* @return mixed
Expand All @@ -222,12 +223,10 @@ public function postCode($project_id, $filename, $zipFilename, $name){
"oauth" => $this->token,
"class_name" => $name,
"options" => array(),
"access_key" => $name);
"access_key" => $name
);

$sendingData = json_encode($sendingData);

// For reference to multi-part encoding in php, see:
// http://vedovini.net/2009/08/posting-multipart-form-data-using-php/
$eol = "\r\n";
$data = '';
$mime_boundary = md5(time());
Expand Down Expand Up @@ -298,6 +297,12 @@ public function deleteSchedule($project_id, $schedule_id){
return $this->apiCall(self::DELETE, $url, $request);
}

/**
* Get information about all schedules for project
*
* @param string $project_id Project ID or empty string
* @return mixed
*/
public function getSchedules($project_id){
$this->setProjectId($project_id);
$this->setJsonHeaders();
Expand All @@ -307,9 +312,30 @@ public function getSchedules($project_id){
}

/**
* @param string $project_id
* @param string $name
* @param array $payload
* Get information about schedule
*
* @param string $project_id Project ID or empty string
* @param string $schedule_id Schedule ID
* @return mixed
* @throws InvalidArgumentException
*/
public function getSchedule($project_id, $schedule_id){
$this->setProjectId($project_id);
if (empty($schedule_id)){
throw new InvalidArgumentException("Please set schedule_id");
}
$this->setJsonHeaders();
$url = "projects/{$this->project_id}/schedules/$schedule_id";

return json_decode($this->apiCall(self::GET, $url));
}

/**
* Schedule task
*
* @param string $project_id Project ID or empty string
* @param string $name Package name
* @param array $payload Payload for task
* @param int $delay delay in seconds
* @return string posted Schedule id
*/
Expand All @@ -318,9 +344,11 @@ public function postScheduleSimple($project_id, $name, $payload = array(), $dela
}

/**
* @param string $project_id
* @param string $name
* @param array $payload
* Schedules task
*
* @param string $project_id Project ID or empty string
* @param string $name Package name
* @param array $payload Payload for task
* @param int $start_at Time of first run in unix timestamp format. Example: time()+2*60
* @param int $run_every Time in seconds between runs. If omitted, task will only run once.
* @param int $end_at Time tasks will stop being enqueued in unix timestamp format.
Expand Down
2 changes: 1 addition & 1 deletion examples/testBasic.php
@@ -1,7 +1,7 @@
<?php
include("../IronWorker.class.php");

$name = "testBasic.php-helloPHP-".microtime(true);
$name = "testBasic-php";

$iw = new IronWorker('config.ini');
$iw->debug_enabled = true;
Expand Down
9 changes: 7 additions & 2 deletions examples/testBasicShedule.php
@@ -1,7 +1,7 @@
<?php
include("../IronWorker.class.php");

$name = "testBasic.php";
$name = "testBasic-Schedule-php";

$iw = new IronWorker('config.ini');
$iw->debug_enabled = true;
Expand All @@ -22,7 +22,12 @@
$start_at = time()+3*60;

# Run task every 2 minutes 10 times
$iw->postScheduleAdvanced($project_id, $name, $payload, $start_at, 2*60, null, 10);
$schedule_id = $iw->postScheduleAdvanced($project_id, $name, $payload, $start_at, 2*60, null, 10);

# Get schedule information
$schedule = $iw->getSchedule($project_id, $schedule_id);
echo "Schedule:\n";
print_r($schedule);

echo "\ndone\n";

Expand Down
2 changes: 1 addition & 1 deletion examples/testBasicSimplest.php
@@ -1,7 +1,7 @@
<?php
include("../IronWorker.class.php");

$name = "testTaskSimple.php-".microtime(true);
$name = "testTaskSimple-php";

$iw = new IronWorker('config.ini');

Expand Down
2 changes: 1 addition & 1 deletion examples/testBatchEmailer.php
@@ -1,7 +1,7 @@
<?php
include("../IronWorker.class.php");

$name = "sendEmail.php-".microtime(true);
$name = "sendEmail-php";

$iw = new IronWorker('config.ini');
$iw->debug_enabled = true;
Expand Down
2 changes: 1 addition & 1 deletion examples/testFFmpeg.php
@@ -1,7 +1,7 @@
<?php
include("../IronWorker.class.php");

$name = "testFFmpeg.php-".microtime(true);
$name = "testFFmpeg-php";

$iw = new IronWorker('config.ini');

Expand Down
2 changes: 1 addition & 1 deletion examples/testFull.php
Expand Up @@ -7,7 +7,7 @@ function tolog($name, $variable, $display = false){
if ($display){echo "{$name}: ".var_export($variable,true)."\n";}
}

$name = "testFull.php-".microtime(true);
$name = "testFull-php";

$project_id = ''; # using default project_id from config

Expand Down
4 changes: 2 additions & 2 deletions examples/testGD_S3.php
Expand Up @@ -3,9 +3,9 @@

$config = parse_ini_file('config.ini', true);

$name = "testGD_S3.php-".microtime(true);
$name = "testGD_S3.php";

$iw = new IronWorker('config_sw.ini');
$iw = new IronWorker('config.ini');

# using default project_id from config
$project_id = "";
Expand Down
2 changes: 1 addition & 1 deletion examples/testMysql.php
@@ -1,7 +1,7 @@
<?php
include("../IronWorker.class.php");

$name = "testMysql.php-".microtime(true);
$name = "testMysql.php";

$iw = new IronWorker('config.ini');
$iw->debug_enabled = true;
Expand Down
2 changes: 1 addition & 1 deletion examples/testPDO.php
@@ -1,7 +1,7 @@
<?php
include("../IronWorker.class.php");

$name = "testPDO.php-".microtime(true);
$name = "testPDO.php";

$config = parse_ini_file('config.ini', true);

Expand Down
2 changes: 1 addition & 1 deletion examples/testPharZend.php
@@ -1,7 +1,7 @@
<?php
include("../IronWorker.class.php");

$name = "testPharZend.php-helloPHP-".microtime(true);
$name = "testPharZend.php";

$iw = new IronWorker('config.ini');
$iw->debug_enabled = true;
Expand Down
2 changes: 1 addition & 1 deletion examples/testRedis.php
@@ -1,7 +1,7 @@
<?php
include("../IronWorker.class.php");

$name = "testRedis.php-".microtime(true);
$name = "testRedis-PHP";

$iw = new IronWorker('config.ini');
$iw->debug_enabled = true;
Expand Down
2 changes: 1 addition & 1 deletion examples/testTwitter.php
@@ -1,7 +1,7 @@
<?php
include("../IronWorker.class.php");

$name = "postToTwitter.php-".microtime(true);
$name = "postToTwitter-php";

$iw = new IronWorker('config.ini');
$iw->debug_enabled = true;
Expand Down

0 comments on commit c25744e

Please sign in to comment.