Example #1
0
    def test_initialization(self):
        from the_tale.common.postponed_tasks.models import PostponedTask
        from the_tale.common.postponed_tasks.prototypes import PostponedTaskPrototype, POSTPONED_TASK_STATE
        from the_tale.common.postponed_tasks.postponed_tasks import FakePostponedInternalTask

        PostponedTaskPrototype.create(FakePostponedInternalTask())

        self.assertEqual(
            PostponedTask.objects.filter(
                state=POSTPONED_TASK_STATE.WAITING).count(), 1)

        self.worker.process_initialize()

        self.assertEqual(
            PostponedTask.objects.filter(
                state=POSTPONED_TASK_STATE.WAITING).count(), 0)
        self.assertEqual(
            PostponedTask.objects.filter(
                state=POSTPONED_TASK_STATE.RESETED).count(), 1)

        self.assertEqual(self.worker.tasks, {})
        self.assertEqual(self.worker.accounts_for_tasks, {})
        self.assertEqual(self.worker.accounts_owners, {
            self.account_1.id: 'game_logic_1',
            self.account_2.id: 'game_logic_2'
        })
        self.assertEqual(self.worker.accounts_queues, {})
        self.assertTrue(self.worker.initialized)
        self.assertFalse(self.worker.wait_next_turn_answer)
        self.assertTrue(GameState.is_working())
Example #2
0
    def cached_ui_info_for_hero(cls, account_id, recache_if_required,
                                patch_turns, for_last_turn):

        data = cache.get(cls.cached_ui_info_key_for_hero(account_id))

        if data is None:
            hero = cls.get_by_account_id(account_id)
            data = hero.ui_info(actual_guaranteed=False)

        cls.modify_ui_info_with_turn(data, for_last_turn=for_last_turn)

        if recache_if_required and cls.is_ui_continue_caching_required(
                data['ui_caching_started_at']) and GameState.is_working():
            environment.workers.supervisor.cmd_start_hero_caching(account_id)

        if patch_turns is not None and data['patch_turn'] in patch_turns:
            patch_fields = set(data['changed_fields'])
            for field in data.keys():
                if field not in patch_fields:
                    del data[field]
        else:
            data['patch_turn'] = None

        del data['changed_fields']

        return data
    def test_initialization(self):
        from the_tale.common.postponed_tasks import PostponedTask, PostponedTaskPrototype, POSTPONED_TASK_STATE, FakePostponedInternalTask

        PostponedTaskPrototype.create(FakePostponedInternalTask())

        self.assertEqual(PostponedTask.objects.filter(state=POSTPONED_TASK_STATE.WAITING).count(), 1)

        self.worker.process_initialize()

        self.assertEqual(PostponedTask.objects.filter(state=POSTPONED_TASK_STATE.WAITING).count(), 0)
        self.assertEqual(PostponedTask.objects.filter(state=POSTPONED_TASK_STATE.RESETED).count(), 1)

        self.assertEqual(self.worker.tasks, {})
        self.assertEqual(self.worker.accounts_for_tasks, {})
        self.assertEqual(self.worker.accounts_owners, {self.account_1.id: 'game_logic_1', self.account_2.id: 'game_logic_2'})
        self.assertEqual(self.worker.accounts_queues, {})
        self.assertTrue(self.worker.initialized)
        self.assertFalse(self.worker.wait_next_turn_answer)
        self.assertTrue(GameState.is_working())
Example #4
0
    def cached_ui_info_for_hero(cls, account_id, recache_if_required, patch_turns, for_last_turn):
        from . import logic

        data = cache.get(cls.cached_ui_info_key_for_hero(account_id))

        if data is None:
            hero = logic.load_hero(account_id=account_id)
            data = hero.ui_info(actual_guaranteed=False)

        cls.modify_ui_info_with_turn(data, for_last_turn=for_last_turn)

        if recache_if_required and cls.is_ui_continue_caching_required(data['ui_caching_started_at']) and GameState.is_working():
            amqp_environment.environment.workers.supervisor.cmd_start_hero_caching(account_id)

        if patch_turns is not None and data['patch_turn'] in patch_turns:
            patch_fields = set(data['changed_fields'])
            for field in data.keys():
                if field not in patch_fields:
                    del data[field]
        else:
            data['patch_turn'] = None

        del data['changed_fields']

        return data
Example #5
0
 def process_no_cmd(self):
     if GameState.is_working():
         self.logger.info('send next turn command')
         environment.workers.supervisor.cmd_next_turn()
Example #6
0
 def process_no_cmd(self):
     if GameState.is_working():
         self.logger.info('send next turn command')
         environment.workers.supervisor.cmd_next_turn()
Example #7
0
 def test_working(self):
     GameState.start()
     self.assertFalse(GameState.is_stopped())
     self.assertTrue(GameState.is_working())
Example #8
0
 def test_no_state(self):
     self.assertTrue(GameState.is_stopped())
     self.assertFalse(GameState.is_working())
Example #9
0
 def test_working(self):
     GameState.start()
     self.assertFalse(GameState.is_stopped())
     self.assertTrue(GameState.is_working())
Example #10
0
 def test_no_state(self):
     self.assertTrue(GameState.is_stopped())
     self.assertFalse(GameState.is_working())