async installAgent()

in src/agentmgr.js [163:234]


    async installAgent(invoker, debug2) {
        this.agentInstalled = true;

        let agentName;

        // base agent on the original action to keep default parameters & annotations
        const agentAction = this.actionWithCode ? clone(this.actionWithCode) : {
            exec: {},
            limits: {},
            annotations: [],
            parameters: []
        };

        // choose the right agent implementation
        let agentCode;
        if (this.argv.ngrok) {
            // user manually requested ngrok
            this.ngrokAgent = new NgrokAgent(this.argv, invoker);

            // agent using ngrok for forwarding
            agentName = "ngrok";
            agentCode = await this.ngrokAgent.getAgent(agentAction);
            debug2("started local ngrok proxy");

        } else {
            this.concurrency = !this.argv.disableConcurrency;

            if (this.concurrency) {
                // normal fast agent using concurrent node.js actions
                agentName = "concurrency";
                agentCode = await this.getConcurrencyAgent();

            } else {
                agentName = "polling activation db";
                agentCode = await this.getPollingActivationDbAgent();
            }
        }

        const backupName = getActionCopyName(this.actionName);

        // create copy in case wskdebug gets killed hard
        // do async as this can be slow for larger actions and this is part of the critical startup path
        this.createBackup = (async () => {
            const debug3 = log.newDebug();

            await this.wsk.actions.update({
                name: backupName,
                action: agentAction
            });
            debug3(`created action backup ${backupName}`);
        })();

        if (this.argv.condition) {
            agentAction.parameters.push({
                key: "$condition",
                value: this.argv.condition
            });
        }

        try {
            await this.pushAgent(agentAction, agentCode, backupName);
        } catch (e) {
            // openwhisk does not support concurrent nodejs actions, try with another
            if (e.statusCode === 400 && e.error && typeof e.error.error === "string" && e.error.error.includes("concurrency")) {
                log.log(`The Openwhisk server does not support concurrent actions, using alternative agent. Consider using --ngrok for a possibly faster agent.`);
                this.concurrency = false;
                agentCode = await this.getPollingActivationDbAgent();
                await this.pushAgent(agentAction, agentCode, backupName);
            }
        }
        debug2(`installed agent type '${agentName}' in place of action '${this.actionName}'`);
    }