コード例 #1
0
ファイル: test_decorators.py プロジェクト: mmclark/seed
    def test_locking(self):
        """Make sure we indicate we're locked if and only if we're inside the function."""
        key = decorators._get_lock_key('fake_func', self.pk)
        self.assertEqual(int(get_lock(key)), self.unlocked)

        @decorators.lock_and_track
        def fake_func(import_file_pk):
            self.assertEqual(int(get_lock(key)), self.locked)

        fake_func(self.pk)

        self.assertEqual(int(get_lock(key)), self.unlocked)
コード例 #2
0
ファイル: test_decorators.py プロジェクト: nW-fr/seed
    def test_locking(self):
        """Make sure we indicate we're locked if and only if we're inside the function."""
        key = decorators._get_lock_key('fake_func', self.pk)
        self.assertEqual(int(get_lock(key)), self.unlocked)

        @decorators.lock_and_track
        def fake_func(import_file_pk):
            self.assertEqual(int(get_lock(key)), self.locked)

        fake_func(self.pk)

        self.assertEqual(int(get_lock(key)), self.unlocked)
コード例 #3
0
ファイル: test_decorators.py プロジェクト: mmclark/seed
    def test_locking_w_exception(self):
        """Make sure we release our lock if we've had an exception."""
        key = decorators._get_lock_key('fake_func', self.pk)

        @decorators.lock_and_track
        def fake_func(import_file_pk):
            self.assertEqual(int(get_lock(key)), self.locked)
            raise TestException('Test exception!')

        self.assertRaises(TestException, fake_func, self.pk)
        # Even though execution failed part way through a call, we unlock.
        self.assertEqual(int(get_lock(key)), self.unlocked)
コード例 #4
0
ファイル: test_decorators.py プロジェクト: nW-fr/seed
    def test_locking_w_exception(self):
        """Make sure we release our lock if we have had an exception."""
        key = decorators._get_lock_key('fake_func', self.pk)

        @decorators.lock_and_track
        def fake_func(import_file_pk):
            self.assertEqual(int(get_lock(key)), self.locked)
            raise TestException('Test exception!')

        self.assertRaises(TestException, fake_func, self.pk)
        # Even though execution failed part way through a call, we unlock.
        self.assertEqual(int(get_lock(key)), self.unlocked)
コード例 #5
0
ファイル: decorators.py プロジェクト: omidtarh/omidtarh
    def _wrapped(import_file_pk, *args, **kwargs):
        """Lock and return progress url for updates."""
        lock_key = _get_lock_key(func_name, import_file_pk)
        prog_key = get_prog_key(func_name, import_file_pk)
        is_locked = get_lock(lock_key)
        # If we're already processing a given task, don't proceed.
        if is_locked:
            return {'error': 'locked'}

        # Otherwise, set the lock for 1 minute.
        lock_cache(lock_key)
        try:
            response = fn(import_file_pk, *args, **kwargs)
        finally:
            # Unset our lock
            unlock_cache(lock_key)

        # If our response is a dict, add our progress URL to it.
        if isinstance(response, dict):
            response['progress_key'] = prog_key

        return response
コード例 #6
0
    def _wrapped(import_file_pk, *args, **kwargs):
        """Lock and return progress url for updates."""
        lock_key = _get_lock_key(func_name, import_file_pk)
        prog_key = get_prog_key(func_name, import_file_pk)
        is_locked = get_lock(lock_key)
        # If we're already processing a given task, don't proceed.
        if is_locked:
            return {'error': 'locked'}

        # Otherwise, set the lock for 1 minute.
        lock_cache(lock_key)
        try:
            response = fn(import_file_pk, *args, **kwargs)
        finally:
            # Unset our lock
            unlock_cache(lock_key)

        # If our response is a dict, add our progress URL to it.
        if isinstance(response, dict):
            response['progress_key'] = prog_key

        return response
コード例 #7
0
ファイル: test_decorators.py プロジェクト: mmclark/seed
 def fake_func(import_file_pk):
     self.assertEqual(int(get_lock(key)), self.locked)
     raise TestException('Test exception!')
コード例 #8
0
ファイル: test_decorators.py プロジェクト: mmclark/seed
 def fake_func(import_file_pk):
     self.assertEqual(int(get_lock(key)), self.locked)
コード例 #9
0
ファイル: test_decorators.py プロジェクト: nW-fr/seed
 def fake_func(import_file_pk):
     self.assertEqual(int(get_lock(key)), self.locked)
     raise TestException('Test exception!')
コード例 #10
0
ファイル: test_decorators.py プロジェクト: nW-fr/seed
 def fake_func(import_file_pk):
     self.assertEqual(int(get_lock(key)), self.locked)