Skip to content

Instantly share code, notes, and snippets.

@codecowboy
Created April 2, 2012 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecowboy/2282089 to your computer and use it in GitHub Desktop.
Save codecowboy/2282089 to your computer and use it in GitHub Desktop.
ironworker
<?php
/*IRON_WORKER_HEADER*/
function getArgs(){
global $argv;
$args = array('task_id' => null, 'dir' => null, 'payload' => array());
foreach($argv as $k => $v){
if (empty($argv[$k+1])) continue;
if ($v == '-id') $args['task_id'] = $argv[$k+1];
if ($v == '-d') $args['dir'] = $argv[$k+1];
if ($v == '-payload' && file_exists($argv[$k+1])){
$args['payload'] = json_decode(file_get_contents($argv[$k+1]));
}
}
return $args;
}
function getPayload(){
$args = getArgs();
return $args['payload'];
}
function setProgress($percent, $msg = ''){
$args = getArgs();
$task_id = $args['task_id'];
$base_url = 'http://worker-aws-us-east-1.iron.io:80/2/';
$project_id = '4f7969d7c032005c1701a639';
$headers = array (
0 => 'Authorization: OAuth ASZJKspQ6MxqZ8A4JgIvd8kCiM4',
1 => 'User-Agent: IronWorker PHP v0.1',
2 => 'Content-Type: application/json',
3 => 'Accept: application/json',
4 => 'Accept-Encoding: gzip, deflate',
);
$url = "{$base_url}projects/$project_id/tasks/$task_id/progress";
$params = array(
'percent' => $percent,
'msg' => $msg
);
$s = curl_init();
curl_setopt($s, CURLOPT_URL, $url);
curl_setopt($s, CURLOPT_POST, true);
curl_setopt($s, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($s, CURLOPT_RETURNTRANSFER, true);
curl_setopt($s, CURLOPT_HTTPHEADER, $headers);
$out = curl_exec($s);
curl_close($s);
return json_decode($out);
}
?><?php
/* This script calls /feeds/[country_code] from the Slim application - see index.php
*
*/
$country_codes = array( 'BR', 'CA', 'US', 'NL' , 'NO', 'ZA', 'ES', 'SE', 'CH', 'UK',
'BE', 'AT', 'DK', 'FI', 'FR', 'DE', 'IT', 'AU', 'JP', 'MY', 'SG');
for ($i=0; $i <= count($country_codes)-1; $i++) {
$url = 'http://fb-sandbox.phpfogapp.com/feed/'.$country_codes[$i];
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
try {
curl_exec($ch);
echo "Populating jobs from $country_codes[$i]"."\n";
} catch( Exception $e) {
error_log($e->getMessage());
echo $e->getMessage();
}
curl_close($ch);
}
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment