Fixed scheduled jobs locking

Move unique key generation to worker class and refactored code a bit.

/cc @krasnoukhov