Javi Prieto
Javi Prieto

Reputation: 429

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

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:

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.

Upvotes: 1

Views: 332

Answers (1)

Maxim Fateev
Maxim Fateev

Reputation: 6870

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.

Upvotes: 1

Related Questions