Save num_sites in the job_stats table as soon as available
Small refactoring
Fixed a few unittests
Merge pull request #1400 from gem/save-num-sites

Save the number of sites in JobStats as soon as it is available