def test_sync_in_progress(self): self.assertFalse(sync.latest_job()) job = models.SyncJob() job.save() self.assertFalse(sync.latest_job().end) now = datetime.datetime.now() job.end = now job.save() self.assertTrue(sync.latest_job().end)
def job(self): """Confirm no sync job is running, otherwise kick off a new one""" job = sync.latest_job() if job and not job.end: # unfinished msg = "Previous job %d started at %s, but not yet finished." % (job.id, job.start) #logger.info(msg) #raise CommandError(msg) else: job = models.SyncJob() job.save() try: self.new_job(job) finally: # tag job as complete logger.info("Finishing job %d" % job.id) job.end = datetime.datetime.now() job.save()