Fix marking a task as PENDING while it is still running 

There was a bug with the history DB where tasks that were already running, and then triggered again (by a different worker) were getting back to state PENDING. They should have stayed at RUNNING. 
The UI was behaving properly but the history db wasn't. 
This PR fixes this.