Beispiel #1
0
 def raise_or_lock(key, timeout):
     now = now_unix()
     result = cache.get(key)
     if result:
         remaining = int(result) - now
         if remaining > 0:
             raise AlreadyQueued(remaining)
     else:
         cache.set(key, now + timeout, timeout)
Beispiel #2
0
    def test_post_409(self, s3_exists_mock, export_source_mock):
        s3_exists_mock.return_value = False
        export_source_mock.delay.side_effect = AlreadyQueued('already-queued')
        response = self.client.post('/sources/source1/v1/export/',
                                    HTTP_AUTHORIZATION='Token ' + self.token,
                                    format='json')

        self.assertEqual(response.status_code, 409)
        s3_exists_mock.assert_called_once_with(
            "username/source1_v1.{}.zip".format(self.v1_updated_at))
        export_source_mock.delay.assert_called_once_with(self.source_v1.id)
Beispiel #3
0
    def test_post_409(self, s3_exists_mock, export_collection_mock):
        s3_exists_mock.return_value = False
        export_collection_mock.apply_async.side_effect = AlreadyQueued('already-queued')
        response = self.client.post(
            '/collections/coll/v1/export/',
            HTTP_AUTHORIZATION='Token ' + self.token,
            format='json'
        )

        self.assertEqual(response.status_code, 409)
        s3_exists_mock.assert_called_once_with("username/coll_v1.{}.zip".format(self.v1_updated_at))
        export_collection_mock.apply_async.assert_called_once_with((self.collection_v1.id, ), queue='concurrent')
Beispiel #4
0
    def test_post_409(self, queue_bulk_import_mock):
        queue_bulk_import_mock.side_effect = AlreadyQueued('already-queued')

        response = self.client.post(
            '/importers/bulk-import/?update_if_exists=true',
            'some-data',
            HTTP_AUTHORIZATION='Token ' + self.token,
            format='json')

        self.assertEqual(response.status_code, 409)
        self.assertEqual(
            response.data,
            dict(exception="The same import has been already queued"))
Beispiel #5
0
    def test_post_409(self, s3_exists_mock, export_source_mock):
        Source.objects.filter(id=self.source_v1.id).update(
            last_child_update='2020-01-01 10:00:00')

        s3_exists_mock.return_value = False
        export_source_mock.delay.side_effect = AlreadyQueued('already-queued')
        response = self.client.post('/sources/source1/v1/export/',
                                    HTTP_AUTHORIZATION='Token ' + self.token,
                                    format='json')

        self.assertEqual(response.status_code, 409)
        s3_exists_mock.assert_called_once_with(
            "username/source1_v1.20200101100000.zip")
        export_source_mock.delay.assert_called_once_with(self.source_v1.id)
Beispiel #6
0
def test_raise_already_queued_graceful():
    example.once_backend.raise_or_lock.side_effect = AlreadyQueued(60)
    result = example.apply_async(once={'graceful': True})
    assert result.result is None
Beispiel #7
0
def test_raise_already_queued():
    example.once_backend.raise_or_lock.side_effect = AlreadyQueued(60)
    with pytest.raises(AlreadyQueued):
        example.apply_async()