Claims and processes Taskcluster work.

        Args:
            context (scriptworker.context.Context): context of worker

        Returns: status code of build
514608
async def invoke(self, context):
        
        try:
            # Note: claim_work(...) might not be safely interruptible! See
            # https://bugzilla.mozilla.org/show_bug.cgi?id=1524069
            tasks = await self._run_cancellable(claim_work(context))
            if not tasks or not tasks.get('tasks', []):
                await self._run_cancellable(asyncio.sleep(context.config['poll_interval']))
                return None

            # Assume only a single task, but should more than one fall through,
            # run them sequentially.  A side effect is our return status will
            # be the status of the final task run.
            status = None
            for task_defn in tasks.get('tasks', []):
                prepare_to_run_task(context, task_defn)
                reclaim_fut = context.event_loop.create_task(reclaim_task(context, context.task))
                try:
                    status = await do_run_task(context, self._run_cancellable, self._to_cancellable_process)
                    artifacts_paths = filepaths_in_dir(context.config['artifact_dir'])
                except WorkerShutdownDuringTask:
                    shutdown_artifact_paths = [os.path.join('public', 'logs', log_file)
                                               for log_file in ['chain_of_trust.log', 'live_backing.log']]
                    artifacts_paths = [path for path in shutdown_artifact_paths
                                       if os.path.isfile(os.path.join(context.config['artifact_dir'], path))]
                    status = STATUSES['worker-shutdown']
                status = worst_level(status, await do_upload(context, artifacts_paths))
                await complete_task(context, status)
                reclaim_fut.cancel()
                cleanup(context)

            return status

        except asyncio.CancelledError:
            return None
1135778
protected boolean addWork(final ForkJoinContext<?> context) {
	requireNotStopped(this);

	final boolean result = workQueue.addWaitingWork(context);
	if (result) {
	    addWorkerIfNeeded();
	}

	return result;
    }
979177
def iter_context_results(context, batch_size=10, task_cache=None):
    """"""

    for futures in iget_batches(context.task_ids, batch_size=batch_size):
        for key, future in futures:
            task = future.get_result()

            if task_cache is not None:
                task_cache[key.id()] = task

            yield key.id(), task
364279
async def claimTask(self, *args, **kwargs):
        

        return await self._makeApiCall(self.funcinfo["claimTask"], *args, **kwargs)
502073
def step_use_curdir_as_working_directory(context):
    
    context.workdir = os.path.abspath(".")
    command_util.ensure_workdir_exists(context)
477799
def register_with_context(self, myname, context):
        

        if self.context is not None:
            raise Exception("attempted to register BuildTarget with multiple "
                            "BuildContexts")

        context.register_task(myname, self)
        self._name = myname
        self.context = context

        for key in self.data_dependencies:
            if type(self.data_dependencies[key]) is DeferredDependency:
                self.data_dependencies[key].parent  = myname
                self.data_dependencies[key].context = context
                for tnmame in self.data_dependencies[key].target_names:
                    context.register_dependency(tnmame, myname)
266859
public void submitContextAndTask(final String evaluatorConfiguration,
                                   final String contextConfiguration,
                                   final String taskConfiguration) {
    this.launchWithConfigurationString(evaluatorConfiguration, contextConfiguration,
        Optional.<String>empty(), Optional.of(taskConfiguration));
  }
1010288
public Object start(IApplicationContext context) {
		Display display = PlatformUI.createDisplay();
		try {
/* FIXME: the static Sisu.lookup utility is currently being reworked...
			int returnCode = PlatformUI.createAndRunWorkbench(display, Sisu.lookup(WorkbenchAdvisor.class));
			if (returnCode == PlatformUI.RETURN_RESTART) {
				return IApplication.EXIT_RESTART;
			}
*/
			return IApplication.EXIT_OK;
		} finally {
			display.dispose();
		}
	}
195943
def extra_context(self, worker_ctx, exc_info):
        
        extra = {}
        extra.update(worker_ctx.context_data)

        self.client.extra_context(extra)
363615
def start(context):
    
    config = context.obj["config"]
    daemon = select(config, "application.daemon", False)
    workspace = select(config, "application.workspace", None)
    pidfile = select(config, "application.pidfile", DEFAULT_PIDFILE)
    daemon_start(partial(main, config), pidfile, daemon, workspace)
1337428
def create_context(self, message_queue, task_id):
        
        parent_data = ParentData(self.parent.kind, self.parent.remote_id)
        path_data = self.local_file.get_path_data()
        params = parent_data, path_data, self.local_file.remote_id
        return UploadContext(self.settings, params, message_queue, task_id)
284017
private synchronized void onContextStatusMessage(final ContextStatusPOJO contextStatus,
                                                   final boolean notifyClientOnNewActiveContext) {

    LOG.log(Level.FINER, "Processing context status message for context {0}", contextStatus.getContextId());
    switch (contextStatus.getContextState()) {
    case READY:
      this.onContextReady(contextStatus, notifyClientOnNewActiveContext);
      break;
    case FAIL:
      this.onContextFailed(contextStatus);
      break;
    case DONE:
      this.onContextDone(contextStatus);
      break;
    default:
      this.onUnknownContextStatus(contextStatus);
      break;
    }
    LOG.log(Level.FINER, "Done processing context status message for context {0}", contextStatus.getContextId());

  }
229797
@Override
	public void setup(TaskContext<GroupReduceFunction<IT, OT>, OT> context) {
		this.taskContext = context;
	}
259282
protected void freeUsed(TopologyAssignContext context) {
        Set<Integer> canFree = new HashSet<>();
        canFree.addAll(context.getAllTaskIds());
        canFree.removeAll(context.getUnstoppedTaskIds());

        Map<String, SupervisorInfo> cluster = context.getCluster();
        Assignment oldAssigns = context.getOldAssignment();
        for (Integer task : canFree) {
            ResourceWorkerSlot worker = oldAssigns.getWorkerByTaskId(task);
            if (worker == null) {
                LOG.warn("No ResourceWorkerSlot of task " + task + " is found when freeing resource");
                continue;
            }

            SupervisorInfo supervisorInfo = cluster.get(worker.getNodeId());
            if (supervisorInfo == null) {
                continue;
            }
            supervisorInfo.getAvailableWorkerPorts().add(worker.getPort());
        }
    }
772746
private void handleUpdate(final NetworkContext context) {
    log.debug(String.format("%s - Network configuration updated in cluster: %s", NetworkManager.this, cluster.address()));
    log.debug(String.format("%s - Scheduling network update task", NetworkManager.this));
    tasks.runTask(new Handler<Task>() {
      @Override
      public void handle(final Task task) {
        // Any time the network is being reconfigured, unready the network.
        // This will cause components to pause during the reconfiguration.
        unready(new Handler<AsyncResult<Void>>() {
          @Override
          public void handle(AsyncResult<Void> result) {
            if (result.failed()) {
              log.error(result.cause());
              task.complete();
            } else {
              if (currentContext != null) {
                final NetworkContext runningContext = currentContext;
                currentContext = context;
                

                // We have to update all instance contexts before deploying
                // any new components in order to ensure connections are
                // available for startup.
                log.info(String.format("%s - Updating network in cluster: %s", NetworkManager.this, address));
                log.debug(String.format("%s - Network:%n%s", NetworkManager.this, currentContext.toString(true)));
                updateNetwork(currentContext, new Handler<AsyncResult<Void>>() {
                  @Override
                  public void handle(AsyncResult<Void> result) {
                    if (result.failed()) {
                      log.warn(result.cause());
                      task.complete();
                    } else {
                      undeployRemovedComponents(currentContext, runningContext, new Handler<AsyncResult<Void>>() {
                        @Override
                        public void handle(AsyncResult<Void> result) {
                          if (result.failed()) {
                            log.warn(result.cause());
                            task.complete();
                          } else {
                            deployAddedComponents(currentContext, runningContext, new Handler<AsyncResult<Void>>() {
                              @Override
                              public void handle(AsyncResult<Void> result) {
                                task.complete();
                                if (result.failed()) {
                                  log.warn(result.cause());
                                }
                              }
                            });
                          }
                        }
                      });
                    }
                  }
                });
              }
              else {
                // Just deploy the entire network if it wasn't already deployed.
                currentContext = context;
                log.info(String.format("%s - Deploying network in cluster: %s", NetworkManager.this, address));
                log.debug(String.format("%s - Network:%n%s", NetworkManager.this, currentContext.toString(true)));
                deployNetwork(context, new Handler<AsyncResult<NetworkContext>>() {
                  @Override
                  public void handle(AsyncResult<NetworkContext> result) {
                    task.complete();
                    if (result.failed()) {
                      log.warn(result.cause());
                    } else {
                      log.info(String.format("%s - Successfully deployed network", NetworkManager.this));
                    }
                  }
                });
              }
            }
          }
        });
      }
    });
  }
520204
def inject_context(context):
    
    context_path = tasks.get_context_path()
    try:
        new_context = json.loads(context)
    except ValueError:
        print('Couldn\'t load context parameter')
        return
    with open(context_path) as jsonfile:
        try:
            jsondata = json.loads(jsonfile.read())
            jsondata.update(new_context)
        except ValueError:
            print('Couldn\'t read context.json')
            return
    with open(context_path, 'w') as jsoncontent:
        json.dump(jsondata, jsoncontent, indent=4)
288846
def get_context_from_cmdln(args, desc="Run scriptworker"):
    
    context = Context()
    parser = argparse.ArgumentParser(description=desc)
    parser.add_argument(
        "config_path", type=str, nargs="?", default="scriptworker.yaml",
        help="the path to the config file"
    )
    parsed_args = parser.parse_args(args)
    context.config, credentials = create_config(config_path=parsed_args.config_path)
    update_logging_config(context)
    return context, credentials