Do agent 'apply' before updating db

* use a transaction for the db commits.

[Finishes #57964476]

Signed-off-by: Tony Hansmann <thansmann@pivotallabs.com>