How to integrate AWS SWF using PHP so it can be managed from a user interface?

340 views Asked by At

I'm using LAMP to build a CMS that allows administrators to upload an MP4 to an Amazon S3 Bucket, convert it several times using Elastic Transcoder, and update the local database so they can be delivered using Cloud Front.

Every step is now working as expected and a simple SWF workflow connects it all (as long as I launch the starter, decider and activity workers from the command line, as I've seen in the examples everywhere).

However, I'm struggling with connecting the pieces together with a user interface:

  • Starting the workflow and launching the decider and activity workers using pcntl_exec when the user starts the upload is the right approach? Any alternatives?
  • The activity workers and the deciders finish execution with every task so they have to be launched again for the next decision or activity, would the workflow starter responsible for launching workers every time or am I missing something?
  • Providing 1. and 2. are going in the right direction, implementing feedback in the UI should be simple using AJAX calls to check the status of the record in the database, which would be updated in each one of the steps. Otherwise, any better way to do it?

EDIT: Someone might find this useful, on point 2:

Program the activity worker to poll for another activity task after it has completed the task at hand. This creates a loop where the activity worker continuously polls for and completes tasks.

Until the decider schedules activity tasks, though, these polls time out with no tasks and your workers just continue polling.

If no decision task is available, Amazon SWF holds the connection open for up to 60 seconds, and returns a task as soon as it becomes available. If no task becomes available, Amazon SWF returns an empty response [...] Make sure to program your decider to poll for another task if it receives an empty response.

1

There are 1 answers

0
Maxim Fateev On BEST ANSWER

I would advise running both activity and decider workers permanently independently from the web server process. You can start them as daemons. They should poll in a loop for new tasks and process them according to your logic. So there is no need to start them again after task execution is complete.

Workflow instances are started from webserver process as starting them is a relatively fast call which doesn't wait for workflow execution completion.

Implementing feedback in UI is usually done by webserver code polling on a special activity type like "UIFeedback". When workflow needs to notify UI about something it schedules this activity which is delivered to the webserver which forwards the activity input data to the AJAX code.