wp_update_post gives 500 internal error

Try using save_post hook instead.

Check this example:
https://gist.github.com/fgilio/38dfbf9d03654b21302a