Who finishes first? Gearman or Mongo PHP insert?

207 views Asked by At

I'm looking at running Gearman ( http://gearman.org) and storing data in Mongo using the Mongo PHP library to manage inserts/updates. So the steps are...

STEPS:

  1. Insert some data into mongo via php mongo insert. When I insert the data I am able to grab the new item "_id" from the initial data object.
  2. Run php snippet to send Gearman server a job to do passing the _id as the data.
  3. The gearman PHP script runs pretty much instantly and grabs the _id from mongo and does some work with it.

My question is... will the data even be in Mongo before gearman starts looking for it. In other words is the _id not a good way to detect if the new data is stored. Is there a way to check this? I need the PHP to be paused (blocked sort of speak) before the PHP code send off the job to gearman since the gearman service will kick in immediately and look for the _id in mongo. Is this possible? My understanding is if the mongo insert runs asynchronously there could be enough lag inserting the item that is longer than the time it takes the gearman php script to start... missing the new _id and the data.

0

There are 0 answers