def resume_job_archiving(): """Resumes archiving of jobs that are stuck in status "archiving". Creates a new celery archival task for each job that has been stuck in status archiving for one day or more. """ from flamenco.celery import job_archival log.info('Creating Celery background tasks for resuming archival of jobs') job_archival.resume_job_archiving()
def test_resume_archiving(self, mock_archive_job): from flamenco.celery import job_archival now = utcnow() # 1 day old in status archiving. Should be resumed. self.force_job_status('archiving', self.job1_id) self.set_job_updated(now - datetime.timedelta(days=1), self.job1_id) # In archiving status but too new. Should *not* be resumed. self.force_job_status('archiving', self.job2_id) self.set_job_updated(now - datetime.timedelta(hours=23), self.job2_id) # 1 day old but in wrong status. Should *not* be resumed. self.set_job_updated(now - datetime.timedelta(days=1), self.job3_id) with mock.patch('pillar.api.utils.utcnow') as mock_utcnow: mock_utcnow.return_value = now job_archival.resume_job_archiving() mock_archive_job.delay.assert_called_once() mock_archive_job.delay.assert_called_with(str(self.job1_id))