PHPTasks

Created: 2012-03-23 12:29
Updated: 2014-03-26 01:07
php

README.md

This simple collection of classes allows for running of tasks in a nice simple way. It can run tasks by defining dependencies and running all the tasks that do not have to wait simultaneously. Of course, the amazon bindings require for you to take care of autoloading everything, including the amazonSDKforPHP.

Please feel free to fork and add new functionality.

Dependencies: you need screen installed. The way it works is:

  1. starts the command in a detached screen
  2. runAndCheckDone verifies if the name of the screen still exists in the list of processes (feel free to extend the checks to include logs, etc)
  3. At some point it's done or it times out and retries. This happens until it runs out of retries.

Also a task will not start until all the dependencies are done and it will try to run them

Here is an example of how to use:

<?php

use Xss\Tasks;

//replace this bit with your own autoload code
if (!spl_autoload_register("Includes::autoload"))
{
    die("Cannot use spl_autoload_register on line: " . __LINE__ . " in file: " . __FILE__ . PHP_EOL);
}


$properties = array('InstanceType' => AmazonEC2::INSTANCE_HIGH_MEM_XLARGE, 'SecurityGroupId' => 'sg-2cf6185b'); //use your own
$machine = new TaskCreateMachine('ami-1f1a236b', $properties); //use your own machine
$sleep = new TaskSleep(120);
$scriptIndexRemote = new TaskExecuteScriptRemotely("ubuntu", //user
                "sudo -u www-data sh -c \"cd /usr/share/nginx/www/deploy/system_scripts/sphinx/ && php /usr/share/nginx/www/deploy/system_scripts/sphinx/sphinx_index.php product_main " . $merchant_id . " " . $part . "\"", //command
                "/home/ubuntu/.ssh/id_rsa.pub", //public key
                "/home/ubuntu/.ssh/id_rsa", //private key
                null, //remote ip
                $machine, //remote machien to get ip - assuming you do not know the IP yet - machine has not started
                22, //port
                3, //retries
                3600); //timeout
$scriptCopyIndexes = new TaskExecuteScriptCopyIndexes("scp IPADDRESS:/usr/local/sphinx/var/data/* /superpacman/newindexes/", $machine,3,300);

$scriptCopyIndexes->addDependency($scriptIndexRemote);
$scriptIndexRemote->addDependency($sleep);
$sleep->addDependency($machine);

while (!TaskBase::runAndCheckDone($scriptCopyIndexes))
{
    sleep(1);
    Includes::log("Pass...");
}
Includes::log("Done");
?>
Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more