def expire_abandoned_assignments(request): """ Security behavior: - Access to this page is limited to requesters. """ (total_deleted, _) = TaskAssignment.expire_all_abandoned() messages.info(request, u'All {} abandoned Tasks have been expired'.format(total_deleted)) return redirect('/admin/turkle')
def handle(self, *args, **options): t0 = datetime.now() (total_deleted, _) = TaskAssignment.expire_all_abandoned() t = datetime.now() dt = (t - t0).total_seconds() logging.basicConfig(format="%(asctime)-15s %(message)s", level=logging.INFO) logging.info('TURKLE: Expired {0} abandoned Task Assignments in {1:.3f} seconds'. format(total_deleted, dt))
def test_expire_all_abandoned__dont_delete_completed(self): t = timezone.now() dt = datetime.timedelta(hours=2) past = t - dt project = Project(login_required=False) project.save() batch = Batch(allotted_assignment_time=1, project=project) batch.save() task = Task(batch=batch) task.save() ha = TaskAssignment( completed=True, expires_at=past, task=task, ) # Bypass TaskAssignment's save(), which updates expires_at super(TaskAssignment, ha).save() self.assertEqual(TaskAssignment.objects.count(), 1) TaskAssignment.expire_all_abandoned() self.assertEqual(TaskAssignment.objects.count(), 1)
def test_expire_all_abandoned(self): t = timezone.now() dt = datetime.timedelta(hours=2) past = t - dt project = Project(login_required=False) project.save() batch = Batch( allotted_assignment_time=1, project=project ) batch.save() task = Task(batch=batch) task.save() ha = TaskAssignment( completed=False, expires_at=past, task=task, ) # Bypass TaskAssignment's save(), which updates expires_at super(TaskAssignment, ha).save() self.assertEqual(TaskAssignment.objects.count(), 1) TaskAssignment.expire_all_abandoned() self.assertEqual(TaskAssignment.objects.count(), 0)
def expire_abandoned_assignments(self, request): (total_deleted, _) = TaskAssignment.expire_all_abandoned() messages.info(request, 'All {} abandoned Tasks have been expired'.format(total_deleted)) return redirect(reverse('turkle_admin:index'))