Scheduler: Check and increase max_execution_time if its too low

Related to #928
Scheduler: Add locking mechanism base on using mysql

Prevent multiple schedulers running at once. We create a fake
locking mechanism based on setting a flag in the settings table.

Related to #928
Optimize cleanup scheduler to only load image media type