MeltwaterArchive / datasift-php

PHP client to interface with DataSift
http://datasift.com/
MIT License
22 stars 6 forks source link

Heartbeat method for StreamConsumer missing? #27

Open marcinrosinski opened 10 years ago

marcinrosinski commented 10 years ago

Hi guys,

been looking at all classes and particularly inside the StreamConsumer interface - https://github.com/datasift/datasift-php/blob/develop/lib/DataSift/IStreamConsumerEventHandler.php - for some heartbeat like functionality/method (being called every x seconds) allowing to report whether script consuming stream is still active or no but can't find anything.

Something like calling a heartbeat() method every 60 seconds so you can implement some custom logging and log consumer state.

Have I missed that or is it not available and if such can be added?

choult commented 10 years ago

Hi @marcinrosinski,

We send "ticks" down the stream every 30 seconds if no data is being sent; this manifests itself as a "connected" status (via the onStatus event) in the PHP client - perhaps that will suffice as a heartbeat for your purposes?

Otherwise, I'm happy to look into a way to solve this for you.

All the best,

Chris Hoult

marcinrosinski commented 10 years ago

Hi @chrishoult

That should be sufficient but would be great to have a heartbeat() method implemented solely on the SDK level in case there would be a problem with ticks not being sent at least heartbeat() would always be invoked.

I have had a look and should be quite easy to do on stream do{} look with simple time() function, every 60sec it calls heartbeat() method where you can do your stuff.

Hope that makes sense but let me know if any questions.

Thanks, /Marcin

choult commented 10 years ago

Feel free to create a PR if you like :)

marcinrosinski commented 10 years ago

Sure @chrishoult I'll get it sorted shortly so you can review and marge once done.

marcinrosinski commented 10 years ago

Hi @chrishoult turns out its not that easy to include in app heartbeat method since you are working in the blocking stream mode hence heartbeat is only called when there is an activity or on "ticks".

Will stick to "ticks" for the time being and let you know in case of any issues.

Thanks for your help.

marcinrosinski commented 10 years ago

Actually there is an issue, it looks like during the very active stream "ticks" are never being sent so there might a place for the heartbeat after all, it would guarantee a consistent "tick" every 30 seconds.

I'll put it in and do PR so you can review.

marcinrosinski commented 10 years ago

OK @chrishoult, I have created PR - https://github.com/datasift/datasift-php/pull/28 - onHeartbeat method is called every 30 seconds in there irrespectively of how busy is a stream.

Let me know if any questions.

marcinrosinski commented 10 years ago

Hi @chrishoult do you have any update regarding PR - https://github.com/datasift/datasift-php/pull/28

choult commented 10 years ago

Sorry for the delay @marcinrosinski - I'm preparing a response :)