def get_task_status(name, create_if_needed=False): """Return the TaskStatus object with the given name.""" metadata = ndb.Key(data_types.TaskStatus, name).get() if not metadata and create_if_needed: metadata = data_types.TaskStatus(id=name) return metadata
def test_run_command_already_running_expired(self): """Test run_command with another instance currently running, but its lease has expired.""" data_types.TaskStatus(id='progression 123 job', bot_name='another_bot', time=datetime.datetime(1970, 1, 1), status='started').put() commands.run_command('progression', '123', 'job') self.assertEqual(1, self.mock.progression_execute_task.call_count) task_status_entities = list(data_types.TaskStatus.query()) self.assertEqual(1, len(task_status_entities)) task_status = task_status_entities[0] self.assertDictEqual( { 'bot_name': 'bot_name', 'status': 'finished', 'time': test_utils.CURRENT_TIME, }, task_status.to_dict())
def test_run_command_already_running(self): """Test run_command with another instance currently running.""" data_types.TaskStatus(id='progression 123 job', bot_name='another_bot', time=test_utils.CURRENT_TIME, status='started').put() with self.assertRaises(commands.AlreadyRunningError): commands.run_command('progression', '123', 'job') self.assertEqual(0, self.mock.progression_execute_task.call_count) task_status_entities = list(data_types.TaskStatus.query()) self.assertEqual(1, len(task_status_entities)) task_status = task_status_entities[0] self.assertDictEqual( { 'bot_name': 'another_bot', 'status': 'started', 'time': test_utils.CURRENT_TIME, }, task_status.to_dict())