public void ScheduleBackupTasks(BackupSchedulerService backupSchedulerService)
        {
            Log.DebugFormat("started to schedule backups");
            var backupsToSchedule = BackupRepository.GetBackupSchedules().Where(schedule => Schedule.IsToBeProcessed(schedule)).ToList();

            Log.DebugFormat("{0} backups are to schedule", backupsToSchedule.Count);
            foreach (var schedule in backupsToSchedule)
            {
                if (!backupSchedulerService.IsStarted)
                {
                    return;
                }
                try
                {
                    var tariff = PaymentManager.GetTariff(schedule.TenantId);
                    if (tariff.State < TariffState.Delay)
                    {
                        schedule.LastBackupTime = DateTime.UtcNow;
                        BackupRepository.SaveBackupSchedule(schedule);
                        Log.DebugFormat("Start scheduled backup: {0}, {1}, {2}, {3}", schedule.TenantId, schedule.BackupMail, schedule.StorageType, schedule.StorageBasePath);
                        BackupWorker.StartScheduledBackup(schedule);
                    }
                    else
                    {
                        Log.DebugFormat("Skip portal {0} not paid", schedule.TenantId);
                    }
                }
                catch (Exception error)
                {
                    Log.Error("error while scheduling backups: {0}", error);
                }
            }
        }
 private void ScheduleBackupTasks()
 {
     if (Monitor.TryEnter(schedulerLock))
     {
         try
         {
             log.DebugFormat("started to schedule backups");
             var backupRepostory   = BackupStorageFactory.GetBackupRepository();
             var backupsToSchedule = backupRepostory.GetBackupSchedules().Where(schedule => schedule.IsToBeProcessed()).ToList();
             log.DebugFormat("{0} backups are to schedule", backupsToSchedule.Count);
             foreach (var schedule in backupsToSchedule)
             {
                 if (!isStarted)
                 {
                     return;
                 }
                 try
                 {
                     if (CoreContext.Configuration.Standalone || CoreContext.TenantManager.GetTenantQuota(schedule.TenantId).AutoBackup)
                     {
                         var tariff = CoreContext.PaymentManager.GetTariff(schedule.TenantId);
                         if (tariff.State < TariffState.Delay)
                         {
                             schedule.LastBackupTime = DateTime.UtcNow;
                             backupRepostory.SaveBackupSchedule(schedule);
                             log.DebugFormat("Start scheduled backup: {0}, {1}, {2}, {3}", schedule.TenantId, schedule.BackupMail, schedule.StorageType, schedule.StorageBasePath);
                             BackupWorker.StartScheduledBackup(schedule);
                         }
                         else
                         {
                             log.DebugFormat("Skip portal {0} not paid", schedule.TenantId);
                         }
                     }
                     else
                     {
                         log.DebugFormat("Skip portal {0} haven't access", schedule.TenantId);
                     }
                 }
                 catch (Exception error)
                 {
                     log.Error("error while scheduling backups: {0}", error);
                 }
             }
         }
         catch (Exception error)
         {
             log.Error("error while scheduling backups: {0}", error);
         }
         finally
         {
             Monitor.Exit(schedulerLock);
         }
     }
 }