src/SA/CpeSdk/CpeActivity.php
public function doActivity()
    {
        $context = [
            'activityArn' => $this->arn,
            'workerName'  => $this->name
        ];

        $this->cpeLogger->logOut("INFO", basename(__FILE__),
                                 "Starting '$this->name' activity tasks polling");

        do {

            try {
                if ($this->debug)
                    $this->cpeLogger->logOut("DEBUG", basename(__FILE__),
                                             "Polling for '$this->name' activity...");

                // Perform Sfn long polling and wait for new tasks to process
                $task = $this->cpeSfnHandler->sfn->getActivityTask($context);

            } catch (\Exception $e) {
                $this->cpeLogger->logOut("ERROR", basename(__FILE__),
                                         "Sfn getActivityTask Failed! " . $e->getMessage(),
                                         $this->logKey);

                // Notify the client if any
                // if ($this->client)
                //     $this->client->onException($context, $e);
            }

            try {
                // Do we have a new activity?
                if (isset($task['taskToken']) && $task['taskToken'] != '') {

                    $this->cpeLogger->logOut("INFO", basename(__FILE__),
                                             "\033[1mNew activity '$this->name' triggered!\033[0m Token: ".$task['taskToken'].".\nSee the Log file for this token: ".$this->cpeLogger->logPath);

                    // Set the logKey so a new log file will be created just for this Execution
                    $this->logKey = substr($task['taskToken'],
                                           strlen($task['taskToken'])-16,
                                           strlen($task['taskToken']) - (strlen($task['taskToken']) - 16));
                    $this->logKey = preg_replace('/[\\\\\/\%\[\]\.\(\)-\/]/s', "_", $this->logKey);
                    $this->token  = $task['taskToken'];
                    if ($this->client)
                        $this->client->logKey = $this->logKey;

                    // Validate the JSON input and set `$this->input`
                    $this->doInputValidation($task['input']);

                    // Notify the client if any
                    if ($this->client)
                        $this->client->onStart($task);

                    // Call the user callback function with the activity input for processing
                    $result = $this->process($task);

                    // Execution successful. We mark it as such and return the output to Sfn
                    $this->activitySuccess($result);
                }
            } catch (\Exception $e) {
                // Notify Sfn that the activity has failed
                $this->activityFail($this->name."Exception", $e->getMessage());
            } finally {
                if (!empty($this->inputFilePath)) {
                    // Remove input file that may have been used. Just to be sure.
                    unlink($this->inputFilePath);
                    $this->inputFilePath = null;
                }
            }

        } while (42);
    }
public function doActivity()
    {
        $context = [
            'activityArn' => $this->arn,
            'workerName'  => $this->name
        ];

        $this->cpeLogger->logOut("INFO", basename(__FILE__),
                                 "Starting '$this->name' activity tasks polling");

        do {

            try {
                if ($this->debug)
                    $this->cpeLogger->logOut("DEBUG", basename(__FILE__),
                                             "Polling for '$this->name' activity...");

                // Perform Sfn long polling and wait for new tasks to process
                $task = $this->cpeSfnHandler->sfn->getActivityTask($context);

            } catch (\Exception $e) {
                $this->cpeLogger->logOut("ERROR", basename(__FILE__),
                                         "Sfn getActivityTask Failed! " . $e->getMessage(),
                                         $this->logKey);

                // Notify the client if any
                // if ($this->client)
                //     $this->client->onException($context, $e);
            }

            try {
                // Do we have a new activity?
                if (isset($task['taskToken']) && $task['taskToken'] != '') {

                    $this->cpeLogger->logOut("INFO", basename(__FILE__),
                                             "\033[1mNew activity '$this->name' triggered!\033[0m Token: ".$task['taskToken'].".\nSee the Log file for this token: ".$this->cpeLogger->logPath);

                    // Set the logKey so a new log file will be created just for this Execution
                    $this->logKey = substr($task['taskToken'],
                                           strlen($task['taskToken'])-16,
                                           strlen($task['taskToken']) - (strlen($task['taskToken']) - 16));
                    $this->logKey = preg_replace('/[\\\\\/\%\[\]\.\(\)-\/]/s', "_", $this->logKey);
                    $this->token  = $task['taskToken'];
                    if ($this->client)
                        $this->client->logKey = $this->logKey;

                    // Validate the JSON input and set `$this->input`
                    $this->doInputValidation($task['input']);

                    // Notify the client if any
                    if ($this->client)
                        $this->client->onStart($task);

                    // Call the user callback function with the activity input for processing
                    $result = $this->process($task);

                    // Execution successful. We mark it as such and return the output to Sfn
                    $this->activitySuccess($result);
                }
            } catch (\Exception $e) {
                // Notify Sfn that the activity has failed
                $this->activityFail($this->name."Exception", $e->getMessage());
            } finally {
                if (!empty($this->inputFilePath)) {
                    // Remove input file that may have been used. Just to be sure.
                    unlink($this->inputFilePath);
                    $this->inputFilePath = null;
                }
            }

        } while (42);
    }
public function doActivity ( ) { $ context = [ 'activityArn' => $ this -> arn , 'workerName' => $ this -> name ] ; $ this -> cpeLogger -> logOut ( "INFO" , basename ( __FILE__ ) , "Starting '$this->name' activity tasks polling" ) ; do { try { if ( $ this -> debug ) $ this -> cpeLogger -> logOut ( "DEBUG" , basename ( __FILE__ ) , "Polling for '$this->name' activity..." ) ; // Perform Sfn long polling and wait for new tasks to process $ task = $ this -> cpeSfnHandler -> sfn -> getActivityTask ( $ context ) ; } catch ( \ Exception $ e ) { $ this -> cpeLogger -> logOut ( "ERROR" , basename ( __FILE__ ) , "Sfn getActivityTask Failed! " . $ e -> getMessage ( ) , $ this -> logKey ) ; // Notify the client if any // if ($this->client) //     $this->client->onException($context, $e); } try { // Do we have a new activity? if ( isset ( $ task [ 'taskToken' ] ) && $ task [ 'taskToken' ] != '' ) { $ this -> cpeLogger -> logOut ( "INFO" , basename ( __FILE__ ) , "\033[1mNew activity '$this->name' triggered!\033[0m Token: " . $ task [ 'taskToken' ] . ".\nSee the Log file for this token: " . $ this -> cpeLogger -> logPath ) ; // Set the logKey so a new log file will be created just for this Execution $ this -> logKey = substr ( $ task [ 'taskToken' ] , strlen ( $ task [ 'taskToken' ] ) - 16 , strlen ( $ task [ 'taskToken' ] ) - ( strlen ( $ task [ 'taskToken' ] ) - 16 ) ) ; $ this -> logKey = preg_replace ( '/[\\\\\/\%\[\]\.\(\)-\/]/s' , "_" , $ this -> logKey ) ; $ this -> token = $ task [ 'taskToken' ] ; if ( $ this -> client ) $ this -> client -> logKey = $ this -> logKey ; // Validate the JSON input and set `$this->input` $ this -> doInputValidation ( $ task [ 'input' ] ) ; // Notify the client if any if ( $ this -> client ) $ this -> client -> onStart ( $ task ) ; // Call the user callback function with the activity input for processing $ result = $ this -> process ( $ task ) ; // Execution successful. We mark it as such and return the output to Sfn $ this -> activitySuccess ( $ result ) ; } } catch ( \ Exception $ e ) { // Notify Sfn that the activity has failed $ this -> activityFail ( $ this -> name . "Exception" , $ e -> getMessage ( ) ) ; } finally { if ( ! empty ( $ this -> inputFilePath ) ) { // Remove input file that may have been used. Just to be sure. unlink ( $ this -> inputFilePath ) ; $ this -> inputFilePath = null ; } } } while ( 42 ) ; }
This must be called fro your activity to start listening for task
Perform Sfn long polling and call user callback function when receiving new activity
This must be called fro your activity to start listening for task Perform Sfn long polling and call user callback function when receiving new activity