Skip to content

Commit

Permalink
Working thru post code, run task, and get log
Browse files Browse the repository at this point in the history
Will need php support on worker, otherwise should work
  • Loading branch information
CloudMarc committed Nov 30, 2011
1 parent 4af3c9d commit f93d117
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
10 changes: 8 additions & 2 deletions SimpleWorker.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ function postTask($project_id, $name){
function getLog($project_id, $task_id){
$this->setProjectId($project_id);
$this->setJsonHeaders();
$url = "projects/$project_id/tasks/$task_id/log/";
$url = "projects/$project_id/tasks/$task_id/log";
$this->headers['Accept'] = "text/plain";
unset($this->headers['Content-Type']);
return $this->apiCall(self::GET, $url);
Expand Down Expand Up @@ -356,6 +356,9 @@ private function apiCall($type, $url, $params = array()){
$this->debug('apiCall url', $url);

$s = curl_init();
if (! isset($params['oauth'])) {
$params['oauth'] = $this->token;
}
switch ($type) {
case self::DELETE:
curl_setopt($s, CURLOPT_URL, $url . '?' . http_build_query($params));
Expand All @@ -367,7 +370,10 @@ private function apiCall($type, $url, $params = array()){
curl_setopt($s, CURLOPT_POSTFIELDS, json_encode($params));
break;
case self::GET:
curl_setopt($s, CURLOPT_URL, $url . '?' . http_build_query($params));
$fullUrl = $url . '?' . http_build_query($params);
$this->debug('apiCall fullUrl', $fullUrl);

curl_setopt($s, CURLOPT_URL, $fullUrl);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion config_sw.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ token = jTxYQDmMx5ZtVeZBT8jVx6oJDLw
api_version = 2
host = 174.129.54.171
port = 8080
default_project_id = 4ebc4c5a20f0c7400f001236
default_project_id = 4ecbde6fcddb133515000001
14 changes: 7 additions & 7 deletions test.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ function tolog($name, $variable, $display = false){
if ($display){echo "{$name}: ".var_export($variable,true)."\n";}
}

$name = "helloPHP-".date('Y-m-d');
$name = "helloPHP-".microtime(true)

#$sw = new SimpleWorker('config_sw.ini');
$sw = new SimpleWorker('config_production.ini');
$sw = new SimpleWorker('config_sw.ini');
//$sw = new SimpleWorker('config_production.ini');
$sw->debug_enabled = true;


Expand Down Expand Up @@ -42,9 +42,9 @@ function tolog($name, $variable, $display = false){
$tasks = $sw->getTasks($projects[0]->id);
tolog('tasks', $tasks);

echo "\n--Get Task Log----------------------------------------\n";
$log = $sw->getLog($projects[0]->id, $tasks[0]->id);
tolog('task_log', $log);
#echo "\n--Get Task Log----------------------------------------\n";
#$log = $sw->getLog($projects[0]->id, $tasks[0]->id);
#tolog('task_log', $log);

echo "\n--Posting Task----------------------------------------\n";
$task_id = $sw->postTask($projects[0]->id, $name);
Expand Down Expand Up @@ -101,4 +101,4 @@ function tolog($name, $variable, $display = false){



echo "\ndone\n";
echo "\ndone\n";
23 changes: 23 additions & 0 deletions testBasic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
include("SimpleWorker.class.php");

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

$sw = new SimpleWorker('config_sw.ini');
//$sw = new SimpleWorker('config_production.ini');
$sw->debug_enabled = true;

$project_id = "4ecbde6fcddb133515000001";
$zipName = $name.'.zip';
$files_to_zip = array('testTask.php');
# if true, good; if false, zip creation failed
$zipFile = SimpleWorker::createZip($files_to_zip, $zipName, true);
$res = $sw->postCode($projects[0]->id, 'testTask.php', $zipName, $name);
$task_id = $sw->postTask($projects_id, $name);
echo "task_id = $task_id \n";

sleep(10);
$log = $sw->getLog($project_id, $task_id);

print_r($log);

2 changes: 2 additions & 0 deletions testTask.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

echo "Hello PHP World!!!\n";
echo microtime(true) . "\n";



0 comments on commit f93d117

Please sign in to comment.