def test_completed_task_creates_sync_log(self):
     restore_config = self._restore_config(async=True)
     restore_config.timing_context.start()
     restore_config.timing_context("wait_for_task_to_start").start()
     get_async_restore_payload.delay(restore_config)
     self.assertTrue(restore_config.timing_context.is_finished())
     self.assertIsNotNone(restore_config.restore_state.current_sync_log)
 def test_completed_task_creates_sync_log(self):
     restore_config = self._restore_config(async=True)
     restore_config.timing_context.start()
     restore_config.timing_context("wait_for_task_to_start").start()
     get_async_restore_payload.delay(restore_config)
     self.assertTrue(restore_config.timing_context.is_finished())
     self.assertIsNotNone(restore_config.restore_state.current_sync_log)
 def test_completed_task_deletes_cache(self):
     cache_id = restore_cache_key(ASYNC_RESTORE_CACHE_KEY_PREFIX,
                                  self.user.user_id)
     restore_config = self._restore_config(async=True)
     restore_config.cache.set(cache_id,
                              'im going to be deleted by the next command')
     get_async_restore_payload.delay(restore_config)
     self.assertIsNone(restore_config.cache.get(cache_id))
Beispiel #4
0
 def test_completed_task_deletes_cache(self):
     async_restore_task_id_cache = AsyncRestoreTaskIdCache(
         domain=self.domain,
         user_id=self.user.user_id,
         sync_log_id=None,
         device_id=None,
     )
     restore_config = self._restore_config(async=True)
     async_restore_task_id_cache.set_value('im going to be deleted by the next command')
     restore_config.timing_context.start()
     restore_config.timing_context("wait_for_task_to_start").start()
     get_async_restore_payload.delay(restore_config)
     self.assertTrue(restore_config.timing_context.is_finished())
     self.assertIsNone(async_restore_task_id_cache.get_value())
Beispiel #5
0
    def _get_asynchronous_payload(self):
        new_task = False
        # fetch the task from celery
        task_id = self.async_restore_task_id_cache.get_value()
        task = AsyncResult(task_id)
        task_exists = task.status == ASYNC_RESTORE_SENT

        if not task_exists:
            # start a new task
            # NOTE this starts a nested timer (wait_for_task_to_start),
            # which will be stopped by self.generate_payload(async_task)
            # in the asynchronous task. It is expected that
            # get_async_restore_payload.delay(self) will serialize this
            # RestoreConfig and it's associated TimingContext before it
            # returns, and thereby fork the timing context. The timing
            # context associated with this side of the fork will not be
            # recorded since it is async (see self.get_response).
            with self.timing_context("wait_for_task_to_start"):
                task = get_async_restore_payload.delay(self, self.domain, self.restore_user.username)
            new_task = True
            # store the task id in cache
            self.async_restore_task_id_cache.set_value(task.id)
        try:
            response = task.get(timeout=self._get_task_timeout(new_task))
        except TimeoutError:
            # return a 202 with progress
            response = AsyncRestoreResponse(task, self.restore_user.username)

        return response
Beispiel #6
0
    def _get_asynchronous_payload(self):
        new_task = False
        # fetch the task from celery
        task_id = self.async_restore_task_id_cache.get_value()
        task = AsyncResult(task_id)
        task_exists = task.status == ASYNC_RESTORE_SENT

        if not task_exists:
            # start a new task
            # NOTE this starts a nested timer (wait_for_task_to_start),
            # which will be stopped by self.generate_payload(async_task)
            # in the asynchronous task. It is expected that
            # get_async_restore_payload.delay(self) will serialize this
            # RestoreConfig and it's associated TimingContext before it
            # returns, and thereby fork the timing context. The timing
            # context associated with this side of the fork will not be
            # recorded since it is async (see self.get_response).
            with self.timing_context("wait_for_task_to_start"):
                task = get_async_restore_payload.delay(
                    self, self.domain, self.restore_user.username)
            new_task = True
            # store the task id in cache
            self.async_restore_task_id_cache.set_value(task.id)
        try:
            response = task.get(timeout=self._get_task_timeout(new_task))
        except TimeoutError:
            # return a 202 with progress
            response = AsyncRestoreResponse(task, self.restore_user.username)

        return response
 def test_completed_task_creates_sync_log(self):
     restore_config = self._restore_config(async=True)
     get_async_restore_payload.delay(restore_config)
     self.assertIsNotNone(restore_config.restore_state.current_sync_log)
Beispiel #8
0
 def test_completed_task_creates_sync_log(self):
     restore_config = self._restore_config(async=True)
     get_async_restore_payload.delay(restore_config)
     self.assertIsNotNone(restore_config.restore_state.current_sync_log)
Beispiel #9
0
 def test_completed_task_deletes_cache(self):
     cache_id = restore_cache_key(ASYNC_RESTORE_CACHE_KEY_PREFIX, self.user.user_id)
     restore_config = self._restore_config(async=True)
     restore_config.cache.set(cache_id, 'im going to be deleted by the next command')
     get_async_restore_payload.delay(restore_config)
     self.assertIsNone(restore_config.cache.get(cache_id))