<?php

/*
 * Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
require_once dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'sdk.class.php';
require_once 'BasicWorkflowWorker.php';
require_once 'cron_example_utils.php';
$swf = new AmazonSWF();
$domain = 'myDomain';
register_domain($swf, $domain, 'my domain', 7);
register_workflow_type($swf, $domain, BasicWorkflowWorker::WORKFLOW_NAME, BasicWorkflowWorker::WORKFLOW_VERSION, 'Periodically runs stuff');
echo "Starting workflow worker polling\n";
$decider_task_list = 'deciderTaskList';
$workflow_worker = new BasicWorkflowWorker($swf, $domain, $decider_task_list);
$workflow_worker->start();
コード例 #2
0
 protected static function _process_event($event, &$workflow_state, &$timer_opts, &$activity_opts, &$continue_as_new_opts, &$max_event_id)
 {
     $event_type = (string) $event->eventType;
     $max_event_id = max($max_event_id, intval($event->eventId));
     if (BasicWorkflowWorker::DEBUG) {
         echo "event type: {$event_type}\n";
         print_r($event);
     }
     switch ($event_type) {
         case 'TimerStarted':
             if ($workflow_state === BasicWorkflowWorkerStates::NOTHING_OPEN || $workflow_state === BasicWorkflowWorkerStates::START) {
                 $workflow_state = BasicWorkflowWorkerStates::TIMER_OPEN;
             } else {
                 if ($workflow_state === BasicWorkflowWorkerStates::ACTIVITY_OPEN) {
                     $workflow_state = BasicWorkflowWorkerStates::TIMER_AND_ACTIVITY_OPEN;
                 }
             }
             break;
         case 'TimerFired':
             if ($workflow_state === BasicWorkflowWorkerStates::TIMER_OPEN) {
                 $workflow_state = BasicWorkflowWorkerStates::NOTHING_OPEN;
             } else {
                 if ($workflow_state === BasicWorkflowWorkerStates::TIMER_AND_ACTIVITY_OPEN) {
                     $workflow_state = BasicWorkflowWorkerStates::ACTIVITY_OPEN;
                 }
             }
             break;
         case 'ActivityTaskScheduled':
             if ($workflow_state === BasicWorkflowWorkerStates::NOTHING_OPEN) {
                 $workflow_state = BasicWorkflowWorkerStates::ACTIVITY_OPEN;
             } else {
                 if ($workflow_state === BasicWorkflowWorkerStates::TIMER_OPEN) {
                     $workflow_state = BasicWorkflowWorkerStates::TIMER_AND_ACTIVITY_OPEN;
                 }
             }
             break;
         case 'ActivityTaskCanceled':
             // add cancellation handling here
         // add cancellation handling here
         case 'ActivityTaskFailed':
             // add failure handling here
             // when an activity fails, a real application may want to retry it or report the incident
         // add failure handling here
         // when an activity fails, a real application may want to retry it or report the incident
         case 'ActivityTaskTimedOut':
             // add timeout handling here
             // when an activity times out, a real application may want to retry it or report the incident
         // add timeout handling here
         // when an activity times out, a real application may want to retry it or report the incident
         case 'ActivityTaskCompleted':
             if ($workflow_state === BasicWorkflowWorkerStates::ACTIVITY_OPEN) {
                 $workflow_state = BasicWorkflowWorkerStates::NOTHING_OPEN;
             } else {
                 if ($workflow_state === BasicWorkflowWorkerStates::TIMER_AND_ACTIVITY_OPEN) {
                     $workflow_state = BasicWorkflowWorkerStates::TIMER_OPEN;
                 }
             }
             break;
             // This is the only case which doesn't only transition state;
             // it also gathers the user's workflow input.
         // This is the only case which doesn't only transition state;
         // it also gathers the user's workflow input.
         case 'WorkflowExecutionStarted':
             $workflow_state = BasicWorkflowWorkerStates::START;
             // gather gather gather
             $event_attributes = $event->workflowExecutionStartedEventAttributes;
             $workflow_input = json_decode($event_attributes->input, true);
             if (BasicWorkflowWorker::DEBUG) {
                 echo 'Workflow input: ';
                 print_r($workflow_input);
             }
             $activity_opts = BasicWorkflowWorker::create_activity_opts_from_workflow_input($workflow_input);
             $timer_opts = BasicWorkflowWorker::create_timer_opts_from_workflow_input($workflow_input);
             $continue_as_new_opts = BasicWorkflowWorker::create_continue_as_new_opts_from_workflow_start($event_attributes);
             break;
     }
 }