Exemple #1
0
 def test_work_horse_force_death(self):
     """Simulate a frozen worker that doesn't observe the timeout properly.
     Fake it by artificially setting the timeout of the parent process to
     something much smaller after the process is already forked.
     """
     fooq = Queue('foo')
     self.assertEqual(fooq.count, 0)
     w = Worker(fooq)
     sentinel_file = '/tmp/.rq_sentinel_work_horse_death'
     if os.path.exists(sentinel_file):
         os.remove(sentinel_file)
     fooq.enqueue(create_file_after_timeout, sentinel_file, 100)
     job, queue = w.dequeue_job_and_maintain_ttl(5)
     w.fork_work_horse(job, queue)
     job.timeout = 5
     w.job_monitoring_interval = 1
     now = utcnow()
     w.monitor_work_horse(job)
     fudge_factor = 1
     total_time = w.job_monitoring_interval + 65 + fudge_factor
     self.assertTrue((utcnow() - now).total_seconds() < total_time)
     self.assertEqual(job.get_status(), JobStatus.FAILED)
     failed_job_registry = FailedJobRegistry(queue=fooq)
     self.assertTrue(job in failed_job_registry)
     self.assertEqual(fooq.count, 0)
Exemple #2
0
 def test_work_horse_death_sets_job_failed(self):
     """worker with an ongoing job whose work horse dies unexpectadly (before
     completing the job) should set the job's status to FAILED
     """
     fooq = Queue('foo')
     self.assertEqual(fooq.count, 0)
     w = Worker(fooq)
     sentinel_file = '/tmp/.rq_sentinel_work_horse_death'
     if os.path.exists(sentinel_file):
         os.remove(sentinel_file)
     fooq.enqueue(create_file_after_timeout, sentinel_file, 100)
     job, queue = w.dequeue_job_and_maintain_ttl(5)
     w.fork_work_horse(job, queue)
     p = Process(target=wait_and_kill_work_horse, args=(w._horse_pid, 0.5))
     p.start()
     w.monitor_work_horse(job)
     job_status = job.get_status()
     p.join(1)
     self.assertEqual(job_status, JobStatus.FAILED)
     failed_job_registry = FailedJobRegistry(queue=fooq)
     self.assertTrue(job in failed_job_registry)
     self.assertEqual(fooq.count, 0)
Exemple #3
0
 def test_work_horse_death_sets_job_failed(self):
     """worker with an ongoing job whose work horse dies unexpectadly (before
     completing the job) should set the job's status to FAILED
     """
     fooq = Queue('foo')
     self.assertEqual(fooq.count, 0)
     w = Worker(fooq)
     sentinel_file = '/tmp/.rq_sentinel_work_horse_death'
     if os.path.exists(sentinel_file):
         os.remove(sentinel_file)
     fooq.enqueue(create_file_after_timeout, sentinel_file, 100)
     job, queue = w.dequeue_job_and_maintain_ttl(5)
     w.fork_work_horse(job, queue)
     p = Process(target=wait_and_kill_work_horse, args=(w._horse_pid, 0.5))
     p.start()
     w.monitor_work_horse(job)
     job_status = job.get_status()
     p.join(1)
     self.assertEqual(job_status, JobStatus.FAILED)
     failed_job_registry = FailedJobRegistry(queue=fooq)
     self.assertTrue(job in failed_job_registry)
     self.assertEqual(fooq.count, 0)