Main workflow switcher.

        This method recreates main workflow from `main wf` dict which
        was set by external workflow swicther previously.
437453
def switch_from_external_to_main_wf(self):

        

        # in external assigned as True in switch_to_external_wf.
        # external_wf should finish EndEvent and it's name should be
        # also EndEvent for switching again to main wf.
        if self.wf_state['in_external'] and self.current.task_type == 'EndEvent' and \
                self.current.task_name == 'EndEvent':

            # main_wf information was copied in switch_to_external_wf and it takes this information.
            main_wf = self.wf_state['main_wf']

            # main_wf_name is assigned to current workflow name again.
            self.current.workflow_name = main_wf['name']

            # For external WF, check permission and authentication. But after cleaning current task.
            self._clear_current_task()

            # check for auth and perm. current task cleared, do against new workflow_name
            self.check_for_authentication()
            self.check_for_permission()

            # WF knowledge is taken for main wf.
            self.workflow_spec = self.get_worfklow_spec()

            # WF instance is started again where leave off.
            self.workflow = self.deserialize_workflow(main_wf['step'])

            # Current WF is this WF instance.
            self.current.workflow = self.workflow

            # in_external is assigned as False
            self.wf_state['in_external'] = False

            # finished is assigned as False, because still in progress.
            self.wf_state['finished'] = False

            # pool info of main_wf is assigned.
            self.wf_state['pool'] = main_wf['pool']
            self.current.pool = self.wf_state['pool']

            # With main_wf is executed.
            self.run()
48993
def system_find_global_workflows(input_params={}, always_retry=True, **kwargs):
    
    return DXHTTPRequest('/system/findGlobalWorkflows', input_params, always_retry=always_retry, **kwargs)
426560
def get_workflows() -> dict:
    
    keys = DB.get_keys("workflow_definitions:*")
    known_workflows = dict()
    for key in keys:
        values = key.split(':')
        if values[1] not in known_workflows:
            known_workflows[values[1]] = list()
        known_workflows[values[1]].append(values[2])

    return known_workflows
376098
def main():
    
    from os import path as op
    from inspect import getfile, currentframe
    from setuptools import setup, find_packages
    from niworkflows.__about__ import (
        __packagename__,
        __author__,
        __email__,
        __maintainer__,
        __license__,
        __description__,
        __longdesc__,
        __url__,
        DOWNLOAD_URL,
        CLASSIFIERS,
        REQUIRES,
        SETUP_REQUIRES,
        LINKS_REQUIRES,
        TESTS_REQUIRES,
        EXTRA_REQUIRES,
    )

    pkg_data = {
        'niworkflows': [
            'data/t1-mni_registration*.json',
            'data/bold-mni_registration*.json',
            'reports/figures.json',
            'reports/fmriprep.yml',
            'reports/report.tpl',
        ]}

    root_dir = op.dirname(op.abspath(getfile(currentframe())))
    version = None
    cmdclass = {}
    if op.isfile(op.join(root_dir, __packagename__, 'VERSION')):
        with open(op.join(root_dir, __packagename__, 'VERSION')) as vfile:
            version = vfile.readline().strip()
        pkg_data[__packagename__].insert(0, 'VERSION')

    if version is None:
        import versioneer
        version = versioneer.get_version()
        cmdclass = versioneer.get_cmdclass()

    setup(
        name=__packagename__,
        version=version,
        description=__description__,
        long_description=__longdesc__,
        author=__author__,
        author_email=__email__,
        maintainer=__maintainer__,
        maintainer_email=__email__,
        license=__license__,
        url=__url__,
        download_url=DOWNLOAD_URL,
        classifiers=CLASSIFIERS,
        packages=find_packages(exclude=['*.tests']),
        zip_safe=False,
        # Dependencies handling
        setup_requires=SETUP_REQUIRES,
        install_requires=list(set(REQUIRES)),
        dependency_links=LINKS_REQUIRES,
        tests_require=TESTS_REQUIRES,
        extras_require=EXTRA_REQUIRES,
        # Data
        package_data=pkg_data,
        include_package_data=True,
        cmdclass=cmdclass,
    )
1290822
def switch(self, payload):
        """"""
        first = payload['first']
        second = payload['second']
        running = self.process_handler.is_running(first) or self.process_handler.is_running(second)
        if running:
            answer = {
                'message': "Can't switch running processes, "
                "please stop the processes before switching them.",
                'status': 'error'
            }

        else:
            switched = self.queue.switch(first, second)
            if switched:
                answer = {
                    'message': 'Entries #{} and #{} switched'.format(first, second),
                    'status': 'success'
                }
            else:
                answer = {'message': "One or both entries do not exist or are not queued/stashed.",
                          'status': 'error'}
        return answer
17463
def real_main(new_url=None,
              baseline_url=None,
              upload_build_id=None,
              upload_release_name=None):
    """"""
    coordinator = workers.get_coordinator()
    fetch_worker.register(coordinator)
    coordinator.start()

    item = UrlPairDiff(
        new_url,
        baseline_url,
        upload_build_id,
        upload_release_name=upload_release_name,
        heartbeat=workers.PrintWorkflow)
    item.root = True

    coordinator.input_queue.put(item)
    coordinator.wait_one()
    coordinator.stop()
    coordinator.join()
129350
def _execute_workflow(cls, process_args):
        
        workflow, input_args, log_path = process_args

        if log_path:
            logger = logging.getLogger()
            logger.setLevel(logging.DEBUG)
            handler = cls._get_log_handler(log_path)
            logger.addHandler(handler)

        stats = {'start_time': dt.datetime.now()}
        try:
            _ = workflow.execute(input_args, monitor=True)
        except BaseException:
            stats['error'] = traceback.format_exc()
        stats['end_time'] = dt.datetime.now()

        if log_path:
            handler.close()
            logger.removeHandler(handler)

        return stats
1258459
def used_artefacts(self,
                       job_order,            # type: Dict
                       process_run_id,       # type: str
                       name=None             # type: str
                      ):  # type: (...) -> None
        """"""
        # FIXME: Use workflow name in packed.cwl, "main" is wrong for nested workflows
        base = "main"
        if name is not None:
            base += "/" + name
        for key, value in job_order.items():
            prov_role = self.wf_ns["%s/%s" % (base, key)]
            entity = self.declare_artefact(value)
            self.document.used(
                process_run_id, entity, datetime.datetime.now(), None,
                {"prov:role": prov_role})
712163
def cbk_qptdm_workflow(self, cbk):
        
        scr_input = cbk.data["input"]
        # Use the WFK file produced by the second
        # Task in the first Work (NSCF step).
        nscf_task = self[0][1]
        wfk_file = nscf_task.outdir.has_abiext("WFK")

        work = self[1]
        work.set_manager(self.manager)
        work.create_tasks(wfk_file, scr_input)
        work.add_deps(cbk.deps)

        work.set_flow(self)
        # Each task has a reference to its work.
        for task in work:
            task.set_work(work)
            # Add the garbage collector.
            if self.gc is not None: task.set_gc(self.gc)

        work.connect_signals()
        work.build()

        return work
1260055
def save_workflow_to_cache(self, serialized_wf_instance):
        
        # self.current.task_data['flow'] = None
        task_data = self.current.task_data.copy()
        for k, v in list(task_data.items()):
            if k.startswith('_'):
                del task_data[k]
        if 'cmd' in task_data:
            del task_data['cmd']

        self.wf_state.update({'step': serialized_wf_instance,
                              'data': task_data,
                              'name': self.current.workflow_name,
                              'wf_id': self.workflow_spec.wf_id
                              })

        if self.current.lane_id:
            self.current.pool[self.current.lane_id] = self.current.role.key
        self.wf_state['pool'] = self.current.pool
        self.current.log.debug("POOL Content before WF Save: %s" % self.current.pool)
        self.current.wf_cache.save(self.wf_state)
591422
def _build_global_workflow(json_spec, args):
    
    # First determine in which regions the global workflow needs to be available
    enabled_regions = _get_validated_enabled_regions(json_spec, args.region)

    # Verify all the stages are also enabled in these regions
    # TODO: Add support for dx building multi-region global workflows with applets
    _assert_executable_regions_match(enabled_regions, json_spec)

    workflows_by_region, projects_by_region = {}, {}  # IDs by region
    try:
        # prepare "regionalOptions" field for the globalworkflow/new input
        workflows_by_region, projects_by_region = \
            _build_underlying_workflows(enabled_regions, json_spec, args)
        regional_options = {}
        for region, workflow_id in workflows_by_region.items():
            regional_options[region] = {'workflow': workflow_id}
        json_spec.update({'regionalOptions': regional_options})

        # leave only fields that are actually used to build the workflow
        gwf_provided_keys = GLOBALWF_SUPPORTED_KEYS.intersection(set(json_spec.keys()))
        gwf_final_json = dict((k, v) for k, v in json_spec.items() if k in gwf_provided_keys)

        # we don't want to print the whole documentation to the screen so we'll remove these fields
        print_spec = copy.deepcopy(gwf_final_json)
        if "description" in gwf_final_json:
            del print_spec["description"]
        if "developerNotes" in gwf_final_json:
            del print_spec["developerNotes"]
        logger.info("Will create global workflow with spec: {}".format(json.dumps(print_spec)))

        # Create a new global workflow version on the platform
        global_workflow_id = dxpy.api.global_workflow_new(gwf_final_json)["id"]

        logger.info("Uploaded global workflow {n}/{v} successfully".format(n=gwf_final_json["name"],
                                                                           v=gwf_final_json["version"]))
        logger.info("You can publish this workflow with:")
        logger.info("  dx publish {n}/{v}".format(n=gwf_final_json["name"],
                                                  v=gwf_final_json["version"]))
    finally:
        # Clean up
        if projects_by_region:
            dxpy.executable_builder.delete_temporary_projects(projects_by_region.values())

    # Set any additional fields on the created workflow
    try:
        _set_categories_on_workflow(global_workflow_id, gwf_final_json.get("categories", []))
    except:
        logger.warn(
            "The workflow {n}/{v} was created but setting categories failed".format(n=gwf_final_json['name'],
                                                                                    v=gwf_final_json['version']))
        raise

    return global_workflow_id
967115
public Workflow getWorkflow(String workflowId, boolean includeTasks) {
        Preconditions.checkArgument(StringUtils.isNotBlank(workflowId), "workflow id cannot be blank");
        WorkflowPb.Workflow workflow = stub.getWorkflowStatus(
                WorkflowServicePb.GetWorkflowStatusRequest.newBuilder()
                        .setWorkflowId(workflowId)
                        .setIncludeTasks(includeTasks)
                        .build()
        );
        return protoMapper.fromProto(workflow);
    }
487836
def complete(self):
        
        if callable(self.task.workflow_complete):
            return self.task.workflow_complete()
        else:
            return super(BaseWorkflowProxy, self).complete()
91433
def change_forms(self, *args, **keywords):
        
        # Returns to previous Form in history if there is a previous Form
        try:
            self.parentApp.switchFormPrevious()
        except Exception as e:  # pragma: no cover
            self.parentApp.switchForm('MAIN')
1162929
public function start()
    {
        $wf = $this->getWorkflowObject();
        if (is_object($wf)) {
            $r = $wf->start($this);
            $this->updateOnAction($wf);
        }

        return $r;
    }
537332
def main(global_config, **settings):
    
    if sys.version_info[0] < 3:
        reload(sys)
        sys.setdefaultencoding('utf-8')

    settings = dict(settings)
    # Scoping sessions for Pyramid ensure session are commit/rollback
    # after the template has been rendered
    create_engine(settings, scoped=True)

    authn_policy = RouteSwitchAuthPolicy(secret=settings['pyshop.cookie_key'],
                                         callback=groupfinder)
    authz_policy = ACLPolicy()
    route_prefix = settings.get('pyshop.route_prefix')

    config = Configurator(settings=settings,
                          root_factory=RootFactory,
                          route_prefix=route_prefix,
                          locale_negotiator=locale_negotiator,
                          authentication_policy=authn_policy,
                          authorization_policy=authz_policy)
    config.end()

    return config.make_wsgi_app()
644951
function (config, cb) {

        var o = {}, k;
        o.domain = this.baseConfig.domain;
        //o.execution = this.workflowId;

        for (k in config) {
            if (config.hasOwnProperty(k)) {
                o[k] = config[k];
            }
        }

        this.swfClient.getWorkflowExecutionHistory(o, cb);
    }