host='35.158.100.160', cli_secret_filepath='golemcli_aws.tck', rpc_cert_filepath='rpc_cert_aws.pem' ) # Here a separate thread for RPC is created. # Now user can send messages to the RPC Component to interact with # remote Golem node. rpc.start() rpc.post({ 'type': 'CreateTask', 'task': { 'type': 'GLambda', 'options': { 'method': my_task, 'args': {'prefix': 'myprefix_string '}, }, 'resources': ['{cwd}/my_input.txt'.format(cwd=os.getcwd())], 'timeout': '00:10:00' } }) # Ignore task created event task_created_evt = rpc.poll(timeout=None) task_results = rpc.poll(timeout=None) # A single response for CreateTask contains TaskResult object # for given task. Example response: # { # 'type': 'TaskResults',
tasks = [ { 'type': 'GLambda', 'options': { 'method': raspa_task, 'args': {'mol': mol} }, 'timeout': '00:10:00' } for mol in files_content_arr ] for t in tasks: rpc.post({ 'type': 'CreateTask', 'task': t }) result_responses = [] # Collect `TaskResults` messages as long as we get a result for each # task we created. while len(result_responses) < len(tasks): response = rpc.poll(timeout=None) if response['type'] == 'TaskResults': result_responses.append(response) else: # There will be other messages in the meantime like: 'TaskCreatedEvent'. # We can simply ignore there for our example. pass
result_json = [f for f in response['results'] if f.endswith('result.json')][0] # Load the file and parse JSON object inside of it. j_obj = json.loads(open(result_json).read()) # Check if there were no errors during computation assert 'error' not in j_obj # Actual result is in 'data' field. data = j_obj['data'] # Verify result assert data == EXPECTED_TASK_RESULT rpc.post({ 'type': 'VerifyResults', 'task_id': response['task_id'], 'subtask_id': response['subtask_id'], 'verdict': SubtaskVerificationState.VERIFIED }) # Wait for `TaskResults` message response = rpc.poll(timeout=None) # A single response for CreateTask contains TaskResult object # for given task. Example response: # { # 'type': 'TaskResults', # 'task_id': '0357c464-2ea2-11e9-97f2-15127dda1506', # 'results': [ # '0357c464-2ea2-11e9-97f2-15127dda1506-output/result.json', # '0357c464-2ea2-11e9-97f2-15127dda1506-output/stdout.log', # '0357c464-2ea2-11e9-97f2-15127dda1506-output/stderr.log'
"options": { "output_path": Path.home().as_posix(), "format": "PNG", "resolution": [400, 300] } } # Golem default installation directory is where we obtain cli_secret_filepath and rpc_cert_filepath datadir = '{home}/.local/share/golem/default/rinkeby'.format(home=Path.home()) # Authenticate with localhost:61000 (default) golem node using cli_secret_filepath # and rpc_cert_filepath specified rpc = RPCComponent( cli_secret_filepath='{datadir}/crossbar/secrets/golemcli.tck'.format( datadir=datadir), rpc_cert_filepath='{datadir}/crossbar/rpc_cert.pem'.format( datadir=datadir)) # Here a separate thread for RPC is created. # Now user can send messages to this the RPC Component to interact with # remote Golem node. rpc.start() # Ignore TaskCreatedEvent _ = rpc.post_wait({'type': 'CreateTask', 'task': blender_dict}) response = rpc.poll(timeout=None) print(response['results']) rpc.post({'type': 'Disconnect'})
'resources': ['{home}/my_input.txt'.format(home=Path.home())], 'timeout': '00:10:00' }, { 'type': 'GLambda', 'options': { 'method': my_task, 'args': { 'prefix': 'myprefix_string ' } }, 'resources': ['{home}/my_input.txt'.format(home=Path.home())], 'timeout': '00:10:00' }] for t in tasks: rpc.post({'type': 'CreateTask', 'task': t}) # NOTE: Results may come unordered. result_responses = [] # Collect `TaskResults` messages as long as we get a result for each # task we created. while len(result_responses) < len(tasks): response = rpc.poll(timeout=None) if response['type'] == 'TaskResults': result_responses.append(response) else: # There will be other messages in the meantime like: 'TaskCreatedEvent'. # We can simply ignore there for our example. pass