@@ -10,6 +10,7 @@ import { Flags } from '@oclif/core';
1010import { Messages } from '@salesforce/core' ;
1111import { QueryResult } from 'jsforce' ;
1212import { cli } from 'cli-ux' ;
13+ import debugFactory from 'debug' ;
1314import Command from '../../../lib/base' ;
1415import { FunctionsFlagBuilder } from '../../../lib/flags' ;
1516import pollForResult from '../../../lib/poll-for-result' ;
@@ -24,6 +25,8 @@ interface FunctionConnectionRecord {
2425Messages . importMessagesDirectory ( __dirname ) ;
2526const messages = Messages . loadMessages ( '@salesforce/plugin-functions' , 'env.create.compute' ) ;
2627
28+ const debug = debugFactory ( 'env:create:compute' ) ;
29+
2730export default class EnvCreateCompute extends Command {
2831 static summary = messages . getMessage ( 'summary' ) ;
2932
@@ -76,56 +79,49 @@ export default class EnvCreateCompute extends Command {
7679 // This query allows us to verify that the org connection has actually been created before
7780 // attempting to create a compute environment. If we don't wait for this to happen, environment
7881 // creation will fail since Heroku doesn't yet know about the org
79- let response : QueryResult < FunctionConnectionRecord > ;
80-
81- try {
82- response = await connection . query < FunctionConnectionRecord > ( `SELECT
82+ const queryStart = new Date ( ) . getTime ( ) ;
83+ const response : QueryResult < FunctionConnectionRecord > = await connection . query < FunctionConnectionRecord > ( `SELECT
8384 Id,
8485 Status,
8586 Error
86- FROM FunctionsConnection` ) ;
87- } catch ( err ) {
88- const error = err as Error ;
89- // This is obviously heinous, but should only exist short-term until the move from `FunctionsConnection`
90- // to `FunctionConnection` is complete. Once that's done, we can remove this and go back to a simple
91- // query against `FunctionConnection`
92- if ( ! error . message . includes ( "sObject type 'FunctionsConnection' is not supported." ) ) {
93- this . error ( error ) ;
94- }
95- response = await connection . query < FunctionConnectionRecord > ( `SELECT
96- Id,
97- Status,
98- Error
99- FROM FunctionConnection` ) ;
100- }
87+ FROM FunctionConnection` ) ;
10188
10289 // If it's a newly created org, we likely won't get anything back for the first few iterations,
10390 // we keep polling
91+ const queryMillis = new Date ( ) . getTime ( ) - queryStart ;
92+ debug ( `query FunctionConnection records=${ response . records . length } millis=${ queryMillis } ` ) ;
10493 if ( ! response . records . length ) {
10594 return false ;
10695 }
10796
10897 const record : FunctionConnectionRecord = response . records [ 0 ] ;
98+ debug ( `record FunctionConnection id=${ record . Id } status=${ record . Status } error=${ record . Error } ` ) ;
10999
110100 // This error is also expected when working with a newly created org. This error just means
111101 // that the devhub hasn't yet enabled functions on the new org (this is an automated async process
112102 // so it takes a bit of time)
113103 if ( record . Error === 'Enable Salesforce Functions from Setup Page' ) {
104+ debug ( `got FunctionConnection.Error=${ record . Error } , devhub Functions setup incomplete` ) ;
114105 return false ;
115106 }
116107
117108 // If there is any other error besides the one mentioned above, something is actually wrong
118109 // and we should bail
119110 if ( record . Error ) {
111+ debug ( `FunctionConnection Error exists (${ record . Error } . Waiting.)` ) ;
120112 this . error ( `${ record . Error } ` ) ;
121113 }
122114
123115 // This is the go signal. Once we have this status it means that the connection is fully up
124116 // and running, and we are good to create a compute environment.
117+ const readyMsg = record . Status === 'TrustedBiDirection' ? 'is ready, proceeding.' : 'NOT ready, waiting.' ;
118+ debug ( `FunctionConnection Status=${ record . Status } ${ readyMsg } ` ) ;
125119 return record . Status === 'TrustedBiDirection' ;
126120 } ) ;
127121
128122 try {
123+ const postStart = new Date ( ) . getTime ( ) ;
124+ debug ( `begin POST /sales-org-connections/${ orgId } /apps sfdx_project_name=${ projectName } ...` ) ;
129125 const { data : app } = await this . client . post < Heroku . App > ( `/sales-org-connections/${ orgId } /apps` , {
130126 headers : {
131127 Accept : 'application/vnd.heroku+json; version=3.evergreen' ,
@@ -136,6 +132,8 @@ export default class EnvCreateCompute extends Command {
136132 } ) ;
137133
138134 cli . action . stop ( ) ;
135+ const postMillis = new Date ( ) . getTime ( ) - postStart ;
136+ debug ( `end POST millis=${ postMillis } app=${ JSON . stringify ( app ) } ` ) ;
139137
140138 this . log ( `New compute environment created with ID ${ app . name } ` ) ;
141139
@@ -173,7 +171,11 @@ export default class EnvCreateCompute extends Command {
173171 }
174172 this . error ( `${ error . data . message } ` ) ;
175173 }
174+ const fetchStart = new Date ( ) . getTime ( ) ;
175+ debug ( `begin GET /sales-org-connections/${ orgId } /apps/${ projectName } ...` ) ;
176176 const app = await fetchAppForProject ( this . client , projectName , org . getUsername ( ) ) ;
177+ const fetchMillis = new Date ( ) . getTime ( ) - fetchStart ;
178+ debug ( `end GET millis=${ fetchMillis } app=${ JSON . stringify ( app ) } ` )
177179 return {
178180 alias,
179181 projectName,
0 commit comments