How to use get_task_data method in yandex-tank

Best Python code snippet using yandex-tank

public.py

Source:public.py Github

copy

Full Screen

...18 def check_permission(cls, request, state, context):19 """Override this method to define who can monitor this task."""20 # pylint: disable=unused-argument21 return False22 def get_task_data(self):23 """Return tuple with state to be set next and results task."""24 state = 'STARTED'25 info = {26 'task_name': self.name,27 'context': self.request.get('permission_context', {}),28 'public_data': self.request.get('public_data', {}),29 }30 return state, info31 def update_progress_data(self):32 state, info = self.get_task_data()33 if STATUS_UPDATES_ENABLED:34 self.update_state(state=state, meta=info)35 def set_permission_context(self, context):36 """37 Set data that can be used by ``check_permission`` to authorize a38 request for the this task. By default it will be the ``kwargs`` passed39 into the task.40 """41 self.request.update(permission_context=context)42 self.update_progress_data()43 def set_public_data(self, data):44 """45 Set data that can be displayed in the frontend to authorized users.46 This might include progress data about the task.47 """48 self.request.update(public_data=data)49 self.update_progress_data()50 def run(self, *args, **kwargs):51 self.set_permission_context(kwargs)52 result = self.run_public(*args, **kwargs)53 if result is not None:54 self.set_public_data(result)55 _, info = self.get_task_data()56 return info57 def after_return(self, status, retval, task_id, args, kwargs, einfo):58 """Add the error to the task data"""59 _, info = self.get_task_data()60 if status == states.FAILURE:61 info['error'] = retval62 if STATUS_UPDATES_ENABLED:63 self.update_state(state=status, meta=info)64def permission_check(check):65 """66 Class decorator for subclasses of PublicTask to sprinkle in re-usable67 permission checks::68 @permission_check(user_id_matches)69 class MyTask(PublicTask):70 def run_public(self, user_id):71 pass72 """73 def decorator(cls):74 cls.check_permission = staticmethod(check)75 return cls76 return decorator77class TaskNoPermission(Exception):78 def __init__(self, task_id, *args, **kwargs):79 message = 'No permission to access task with id {id}'.format(80 id=task_id)81 super(TaskNoPermission, self).__init__(message, *args, **kwargs)82def get_public_task_data(request, task_id):83 """84 Return task details as tuple85 Will raise `TaskNoPermission` if `request` has no permission to access info86 of the task with id `task_id`. This is also the case of no task with the87 given id exists.88 :returns: (task name, task state, public data, error message)89 :rtype: (str, str, dict, str)90 """91 try:92 task, state, info = get_task_data(task_id)93 except TaskNotFound:94 # No task info has been found act like we don't have permission to see95 # the results.96 raise TaskNoPermission(task_id)97 if not hasattr(task, 'check_permission'):98 raise TaskNoPermission(task_id)99 context = info.get('context', {})100 if not task.check_permission(request, state, context):101 raise TaskNoPermission(task_id)102 public_name = task.public_name...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run yandex-tank automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful