code: def test_nested_jobs(node):
      client = node.login(
          email="info@openmined.org", password="changethis"
      )
  
      res = client.register(
          name="a", email="aa@b.org", password="c", password_verify="c"
      )
      assert isinstance(res, SyftSuccess)
      ds_client = node.login(email="aa@b.org", password="c")
      ## Dataset
  
      x = ActionObject.from_obj([1, 2])
      x_ptr = x.send(ds_client)
  
      ## aggregate function
      @sy.syft_function()
      def aggregate_job(job_results):
          return sum(job_results)
  
      aggregate_job.code = dedent(aggregate_job.code)
      res = ds_client.code.submit(aggregate_job)
  
      ## Batch function
      @syft_function()
      def process_batch(batch):
          print(f"starting batch {batch}")
          return batch + 1
  
      process_batch.code = dedent(process_batch.code)
  
      res = ds_client.code.submit(process_batch)
      print(res)
  
      ## Main function
  
      @syft_function_single_use(x=x_ptr)
      def process_all(domain, x):
          job_results = []
          for elem in x:
              batch_job = domain.launch_job(process_batch, batch=elem)
              job_results += [batch_job.result]
  
          job = domain.launch_job(
              aggregate_job, job_results=job_results
          )
          return job.result
  
      process_all.code = dedent(process_all.code)
      assert process_all.worker_pool_id is None
  
      # Approve & run
      res = ds_client.code.request_code_execution(process_all)
      print(res)
      assert not isinstance(res, SyftError)
  
      assert ds_client.code[-1].worker_pool_id is not None
      client.requests[-1].approve(approve_nested=True)
  
      job = ds_client.code.process_all(x=x_ptr, blocking=False)
  
      job.wait()
      # stdlib
  
      assert len(job.subjobs) == 3
      # stdlib
  
      sub_results = [j.wait().get() for j in job.subjobs]
      assert set(sub_results) == {2, 3, 5}
      assert job.result.wait().get() == 5
  
      job = client.jobs[-1]
      assert job.job_worker_id is not None
  
file_path: PySyft/packages/syft/tests/syft/syft_functions/syft_function_test.py
imports: import random
  import sys
  from textwrap import dedent
  import pytest
  import syft
  from syft import ActionObject
  from syft import syft_function
  from syft import syft_function_single_use
  from syft.service.response import SyftError
  from syft.service.response import SyftSuccess
label_desc: Use image node_id 2 for calling a global function with example usage: test_nested_jobs(node) and returns: sum, unknown, job