eas-cli 23.0.0 → 23.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +174 -149
- package/build/api.d.ts +1 -0
- package/build/api.js +12 -0
- package/build/commandUtils/new/commands.d.ts +16 -1
- package/build/commandUtils/new/commands.js +59 -20
- package/build/commandUtils/new/projectFiles.d.ts +2 -1
- package/build/commandUtils/new/projectFiles.js +24 -1
- package/build/commandUtils/new/sdkVersion.d.ts +17 -0
- package/build/commandUtils/new/sdkVersion.js +138 -0
- package/build/commandUtils/workflow/logs/fetchLogs.d.ts +5 -0
- package/build/commandUtils/workflow/logs/fetchLogs.js +24 -0
- package/build/commandUtils/workflow/logs/parseLogs.d.ts +14 -0
- package/build/commandUtils/workflow/logs/parseLogs.js +69 -0
- package/build/commandUtils/workflow/logs/watcher.d.ts +32 -0
- package/build/commandUtils/workflow/logs/watcher.js +162 -0
- package/build/commandUtils/workflow/stateMachine.js +2 -1
- package/build/commandUtils/workflow/types.d.ts +12 -5
- package/build/commandUtils/workflow/utils.d.ts +9 -5
- package/build/commandUtils/workflow/utils.js +144 -146
- package/build/commands/project/new.d.ts +1 -0
- package/build/commands/project/new.js +13 -2
- package/build/commands/simulator/get.js +2 -0
- package/build/commands/simulator/index.d.ts +1 -0
- package/build/commands/simulator/index.js +10 -0
- package/build/commands/simulator/list.d.ts +1 -0
- package/build/commands/simulator/list.js +9 -0
- package/build/commands/workflow/run.d.ts +8 -0
- package/build/commands/workflow/run.js +27 -0
- package/build/commands/workflow/ssh.d.ts +31 -0
- package/build/commands/workflow/ssh.js +190 -0
- package/build/graphql/generated.d.ts +243 -3
- package/build/graphql/generated.js +28 -4
- package/build/graphql/mutations/RealtimeLogsMutation.d.ts +6 -0
- package/build/graphql/mutations/RealtimeLogsMutation.js +40 -0
- package/build/graphql/mutations/WorkflowRunMutation.d.ts +3 -2
- package/build/graphql/mutations/WorkflowRunMutation.js +4 -1
- package/build/graphql/queries/DeviceRunSessionQuery.js +5 -0
- package/build/graphql/queries/WorkflowJobSshQuery.d.ts +20 -0
- package/build/graphql/queries/WorkflowJobSshQuery.js +133 -0
- package/build/ora.d.ts +7 -0
- package/build/ora.js +12 -0
- package/build/simulator/utils.js +9 -1
- package/build/utils/centrifuge.d.ts +10 -0
- package/build/utils/centrifuge.js +89 -0
- package/build/utils/expodash/uniqBy.js +3 -2
- package/build/worker/upload.d.ts +14 -1
- package/build/worker/upload.js +81 -17
- package/oclif.manifest.json +397 -287
- package/package.json +12 -10
- package/build/commandUtils/workflow/fetchLogs.d.ts +0 -6
- package/build/commandUtils/workflow/fetchLogs.js +0 -44
- package/build/onboarding/git.d.ts +0 -16
- package/build/onboarding/git.js +0 -88
|
@@ -33,6 +33,7 @@ exports.DeviceRunSessionQuery = {
|
|
|
33
33
|
byId(deviceRunSessionId: $deviceRunSessionId) {
|
|
34
34
|
id
|
|
35
35
|
name
|
|
36
|
+
tags
|
|
36
37
|
status
|
|
37
38
|
type
|
|
38
39
|
platform
|
|
@@ -78,6 +79,9 @@ exports.DeviceRunSessionQuery = {
|
|
|
78
79
|
... on ServeSimRunSessionRemoteConfig {
|
|
79
80
|
previewUrl
|
|
80
81
|
}
|
|
82
|
+
... on WebPreviewOnlyRunSessionRemoteConfig {
|
|
83
|
+
previewUrl: webPreviewUrl
|
|
84
|
+
}
|
|
81
85
|
}
|
|
82
86
|
turtleJobRun {
|
|
83
87
|
id
|
|
@@ -108,6 +112,7 @@ exports.DeviceRunSessionQuery = {
|
|
|
108
112
|
node {
|
|
109
113
|
id
|
|
110
114
|
name
|
|
115
|
+
tags
|
|
111
116
|
status
|
|
112
117
|
type
|
|
113
118
|
platform
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ExpoGraphqlClient } from '../../commandUtils/context/contextUtils/createGraphqlClient';
|
|
2
|
+
export type WorkflowJobSshConnectionConfig = {
|
|
3
|
+
host: string;
|
|
4
|
+
secret: string;
|
|
5
|
+
reconnecting: boolean;
|
|
6
|
+
};
|
|
7
|
+
export type WorkflowJobSshSession = {
|
|
8
|
+
id: string;
|
|
9
|
+
connectionConfig: WorkflowJobSshConnectionConfig;
|
|
10
|
+
};
|
|
11
|
+
export type WorkflowJobSshConnectInfo = {
|
|
12
|
+
sshRequested: boolean;
|
|
13
|
+
jobCompleted: boolean;
|
|
14
|
+
session: WorkflowJobSshSession | null;
|
|
15
|
+
};
|
|
16
|
+
export declare const WorkflowJobSshQuery: {
|
|
17
|
+
connectInfoForWorkflowJobAsync(graphqlClient: ExpoGraphqlClient, workflowJobId: string): Promise<WorkflowJobSshConnectInfo | null>;
|
|
18
|
+
connectInfoForJobRunAsync(graphqlClient: ExpoGraphqlClient, jobRunId: string): Promise<WorkflowJobSshConnectInfo | null>;
|
|
19
|
+
connectInfoForResourceIdAsync(graphqlClient: ExpoGraphqlClient, resourceId: string): Promise<WorkflowJobSshConnectInfo | null>;
|
|
20
|
+
};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WorkflowJobSshQuery = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag"));
|
|
6
|
+
const client_1 = require("../client");
|
|
7
|
+
const generated_1 = require("../generated");
|
|
8
|
+
const FINAL_WORKFLOW_JOB_STATUSES = new Set([
|
|
9
|
+
generated_1.WorkflowJobStatus.Success,
|
|
10
|
+
generated_1.WorkflowJobStatus.Failure,
|
|
11
|
+
generated_1.WorkflowJobStatus.Canceled,
|
|
12
|
+
generated_1.WorkflowJobStatus.Skipped,
|
|
13
|
+
]);
|
|
14
|
+
const FINAL_JOB_RUN_STATUSES = new Set([
|
|
15
|
+
generated_1.JobRunStatus.Errored,
|
|
16
|
+
generated_1.JobRunStatus.Finished,
|
|
17
|
+
generated_1.JobRunStatus.Canceled,
|
|
18
|
+
]);
|
|
19
|
+
function toConnectInfo(job) {
|
|
20
|
+
const hasTurtleTarget = job.turtleJobRun != null || job.turtleBuild != null;
|
|
21
|
+
return {
|
|
22
|
+
sshRequested: hasTurtleTarget && job.workflowRun.sshSettings != null,
|
|
23
|
+
jobCompleted: FINAL_WORKFLOW_JOB_STATUSES.has(job.status),
|
|
24
|
+
session: job.turtleJobRun?.sshSession ?? job.turtleBuild?.sshSession ?? null,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function isNotFoundError(error) {
|
|
28
|
+
if (!(error instanceof client_1.GraphqlError)) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
return error.graphQLErrors.some(e => {
|
|
32
|
+
const code = e?.extensions?.errorCode ?? e?.extensions?.code;
|
|
33
|
+
return (code === 'ENTITY_NOT_FOUND' ||
|
|
34
|
+
/Entity not found/i.test(e?.message ?? '') ||
|
|
35
|
+
/not found/i.test(e?.message ?? ''));
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
exports.WorkflowJobSshQuery = {
|
|
39
|
+
async connectInfoForWorkflowJobAsync(graphqlClient, workflowJobId) {
|
|
40
|
+
let data;
|
|
41
|
+
try {
|
|
42
|
+
data = await (0, client_1.withErrorHandlingAsync)(graphqlClient
|
|
43
|
+
.query((0, graphql_tag_1.default) `
|
|
44
|
+
query WorkflowJobSshPoll($workflowJobId: ID!) {
|
|
45
|
+
workflowJobs {
|
|
46
|
+
byId(workflowJobId: $workflowJobId) {
|
|
47
|
+
id
|
|
48
|
+
status
|
|
49
|
+
workflowRun {
|
|
50
|
+
id
|
|
51
|
+
sshSettings {
|
|
52
|
+
idleTimeoutSeconds
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
turtleJobRun {
|
|
56
|
+
id
|
|
57
|
+
sshSession {
|
|
58
|
+
id
|
|
59
|
+
connectionConfig {
|
|
60
|
+
host
|
|
61
|
+
secret
|
|
62
|
+
reconnecting
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
turtleBuild {
|
|
67
|
+
id
|
|
68
|
+
sshSession {
|
|
69
|
+
id
|
|
70
|
+
connectionConfig {
|
|
71
|
+
host
|
|
72
|
+
secret
|
|
73
|
+
reconnecting
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
`, { workflowJobId }, { requestPolicy: 'network-only' })
|
|
81
|
+
.toPromise());
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
if (isNotFoundError(error)) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
return toConnectInfo(data.workflowJobs.byId);
|
|
90
|
+
},
|
|
91
|
+
async connectInfoForJobRunAsync(graphqlClient, jobRunId) {
|
|
92
|
+
let data;
|
|
93
|
+
try {
|
|
94
|
+
data = await (0, client_1.withErrorHandlingAsync)(graphqlClient
|
|
95
|
+
.query((0, graphql_tag_1.default) `
|
|
96
|
+
query JobRunSshPoll($jobRunId: ID!) {
|
|
97
|
+
jobRun {
|
|
98
|
+
byId(jobRunId: $jobRunId) {
|
|
99
|
+
id
|
|
100
|
+
status
|
|
101
|
+
sshSession {
|
|
102
|
+
id
|
|
103
|
+
connectionConfig {
|
|
104
|
+
host
|
|
105
|
+
secret
|
|
106
|
+
reconnecting
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
`, { jobRunId }, { requestPolicy: 'network-only' })
|
|
113
|
+
.toPromise());
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
if (isNotFoundError(error)) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
const jobRun = data.jobRun.byId;
|
|
122
|
+
const jobCompleted = FINAL_JOB_RUN_STATUSES.has(jobRun.status);
|
|
123
|
+
return {
|
|
124
|
+
sshRequested: jobRun.sshSession != null || jobCompleted,
|
|
125
|
+
jobCompleted,
|
|
126
|
+
session: jobRun.sshSession,
|
|
127
|
+
};
|
|
128
|
+
},
|
|
129
|
+
async connectInfoForResourceIdAsync(graphqlClient, resourceId) {
|
|
130
|
+
return ((await exports.WorkflowJobSshQuery.connectInfoForWorkflowJobAsync(graphqlClient, resourceId)) ??
|
|
131
|
+
(await exports.WorkflowJobSshQuery.connectInfoForJobRunAsync(graphqlClient, resourceId)));
|
|
132
|
+
},
|
|
133
|
+
};
|
package/build/ora.d.ts
CHANGED
|
@@ -7,3 +7,10 @@ export { Ora, Options };
|
|
|
7
7
|
* @returns
|
|
8
8
|
*/
|
|
9
9
|
export declare function ora(options?: Options | string): Ora;
|
|
10
|
+
/**
|
|
11
|
+
* Updates the text of a spinner. Does nothing if new text is the same as old text to prevent flickering.
|
|
12
|
+
*/
|
|
13
|
+
export declare function updateSpinnerText(spinner: Ora, { prefixText, text }: {
|
|
14
|
+
prefixText?: string;
|
|
15
|
+
text?: string;
|
|
16
|
+
}): void;
|
package/build/ora.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ora = ora;
|
|
4
|
+
exports.updateSpinnerText = updateSpinnerText;
|
|
4
5
|
const tslib_1 = require("tslib");
|
|
5
6
|
const getenv_1 = require("getenv");
|
|
6
7
|
// eslint-disable-next-line
|
|
@@ -99,3 +100,14 @@ function ora(options) {
|
|
|
99
100
|
};
|
|
100
101
|
return spinner;
|
|
101
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Updates the text of a spinner. Does nothing if new text is the same as old text to prevent flickering.
|
|
105
|
+
*/
|
|
106
|
+
function updateSpinnerText(spinner, { prefixText, text }) {
|
|
107
|
+
if (prefixText !== undefined && spinner.prefixText !== prefixText) {
|
|
108
|
+
spinner.prefixText = prefixText;
|
|
109
|
+
}
|
|
110
|
+
if (text !== undefined && spinner.text !== text) {
|
|
111
|
+
spinner.text = text;
|
|
112
|
+
}
|
|
113
|
+
}
|
package/build/simulator/utils.js
CHANGED
|
@@ -26,6 +26,7 @@ exports.DEVICE_RUN_SESSION_TYPE_FLAG_VALUES = {
|
|
|
26
26
|
[generated_1.DeviceRunSessionType.Appium]: 'appium',
|
|
27
27
|
[generated_1.DeviceRunSessionType.Argent]: 'argent',
|
|
28
28
|
[generated_1.DeviceRunSessionType.ServeSim]: 'web-preview-only',
|
|
29
|
+
[generated_1.DeviceRunSessionType.WebPreviewOnly]: 'web-preview-only',
|
|
29
30
|
};
|
|
30
31
|
exports.DEVICE_RUN_SESSION_TYPE_BY_FLAG_VALUE = Object.fromEntries(Object.entries(exports.DEVICE_RUN_SESSION_TYPE_FLAG_VALUES).map(([type, value]) => [value, type]));
|
|
31
32
|
function deviceRunSessionTypeToFlagValue(type) {
|
|
@@ -54,6 +55,7 @@ function getRemoteSessionEnvironmentVariables(remoteConfig) {
|
|
|
54
55
|
APPIUM_CAPS: JSON.stringify(remoteConfig.capabilities),
|
|
55
56
|
};
|
|
56
57
|
case 'ServeSimRunSessionRemoteConfig':
|
|
58
|
+
case 'WebPreviewOnlyRunSessionRemoteConfig':
|
|
57
59
|
return {};
|
|
58
60
|
}
|
|
59
61
|
}
|
|
@@ -123,7 +125,7 @@ function formatRemoteSessionInstructions(remoteConfig, configType) {
|
|
|
123
125
|
'<appium-client> [args...]',
|
|
124
126
|
];
|
|
125
127
|
if (remoteConfig.webPreviewUrl) {
|
|
126
|
-
lines.push('', 'Open the
|
|
128
|
+
lines.push('', 'Open the simulator preview:', '', remoteConfig.webPreviewUrl);
|
|
127
129
|
}
|
|
128
130
|
return lines.join('\n');
|
|
129
131
|
}
|
|
@@ -133,5 +135,11 @@ function formatRemoteSessionInstructions(remoteConfig, configType) {
|
|
|
133
135
|
'',
|
|
134
136
|
remoteConfig.previewUrl,
|
|
135
137
|
].join('\n');
|
|
138
|
+
case 'WebPreviewOnlyRunSessionRemoteConfig':
|
|
139
|
+
return [
|
|
140
|
+
'🌐 Open the following URL in your browser to access the simulator:',
|
|
141
|
+
'',
|
|
142
|
+
remoteConfig.previewUrl,
|
|
143
|
+
].join('\n');
|
|
136
144
|
}
|
|
137
145
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ExpoGraphqlClient } from '../commandUtils/context/contextUtils/createGraphqlClient';
|
|
2
|
+
import { RealtimeLogsMutationGenerateCentrifugoSubscriptionTokenArgs } from '../graphql/generated';
|
|
3
|
+
export type RealtimeLogsSubscription = {
|
|
4
|
+
close: () => void;
|
|
5
|
+
};
|
|
6
|
+
export type RealtimeLogsClient = {
|
|
7
|
+
subscribeAsync: (args: RealtimeLogsMutationGenerateCentrifugoSubscriptionTokenArgs, onPublication: (data: unknown) => void) => Promise<RealtimeLogsSubscription | null>;
|
|
8
|
+
close: () => void;
|
|
9
|
+
};
|
|
10
|
+
export declare function createRealtimeLogsClient(graphqlClient: ExpoGraphqlClient): RealtimeLogsClient | null;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRealtimeLogsClient = createRealtimeLogsClient;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const centrifuge_1 = require("centrifuge");
|
|
6
|
+
const ws_1 = tslib_1.__importDefault(require("ws"));
|
|
7
|
+
const api_1 = require("../api");
|
|
8
|
+
const RealtimeLogsMutation_1 = require("../graphql/mutations/RealtimeLogsMutation");
|
|
9
|
+
const fetch_1 = require("../fetch");
|
|
10
|
+
const log_1 = tslib_1.__importDefault(require("../log"));
|
|
11
|
+
function createProxiedWebSocketConstructor(agent) {
|
|
12
|
+
return class ProxiedWebSocket extends ws_1.default {
|
|
13
|
+
constructor(address, protocols) {
|
|
14
|
+
super(address, protocols, { agent });
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function createWebSocketConstructor() {
|
|
19
|
+
return fetch_1.httpsProxyAgent ? createProxiedWebSocketConstructor(fetch_1.httpsProxyAgent) : ws_1.default;
|
|
20
|
+
}
|
|
21
|
+
function createRealtimeLogsClient(graphqlClient) {
|
|
22
|
+
const getTokenAsync = async () => {
|
|
23
|
+
const { token } = await RealtimeLogsMutation_1.RealtimeLogsMutation.generateCentrifugoConnectionTokenAsync(graphqlClient);
|
|
24
|
+
return token;
|
|
25
|
+
};
|
|
26
|
+
let client;
|
|
27
|
+
try {
|
|
28
|
+
client = new centrifuge_1.Centrifuge((0, api_1.getEASLogsWebsocketUrl)(), {
|
|
29
|
+
websocket: createWebSocketConstructor(),
|
|
30
|
+
getToken: getTokenAsync,
|
|
31
|
+
});
|
|
32
|
+
client.on('error', ({ error }) => {
|
|
33
|
+
log_1.default.debug(`Realtime logs connection error: ${error.message}`);
|
|
34
|
+
});
|
|
35
|
+
client.connect();
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
log_1.default.debug(`Failed to connect to realtime logs: ${err.message}`);
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
subscribeAsync: async (args, onPublication) => {
|
|
43
|
+
const getSubscriptionTokenAsync = async () => {
|
|
44
|
+
const { token } = await RealtimeLogsMutation_1.RealtimeLogsMutation.generateCentrifugoSubscriptionTokenAsync(graphqlClient, args);
|
|
45
|
+
return token;
|
|
46
|
+
};
|
|
47
|
+
try {
|
|
48
|
+
const { channel, token } = await RealtimeLogsMutation_1.RealtimeLogsMutation.generateCentrifugoSubscriptionTokenAsync(graphqlClient, args);
|
|
49
|
+
const subscription = client.newSubscription(channel, {
|
|
50
|
+
token,
|
|
51
|
+
getToken: getSubscriptionTokenAsync,
|
|
52
|
+
});
|
|
53
|
+
subscription.on('error', ({ error }) => {
|
|
54
|
+
log_1.default.debug(`Realtime logs subscription error on ${channel}: ${error.message}`);
|
|
55
|
+
});
|
|
56
|
+
subscription.on('publication', ({ data }) => {
|
|
57
|
+
onPublication(data);
|
|
58
|
+
});
|
|
59
|
+
subscription.subscribe();
|
|
60
|
+
return {
|
|
61
|
+
close: () => {
|
|
62
|
+
closeSubscription(client, subscription);
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
log_1.default.debug(`Failed to subscribe to realtime logs: ${err.message}`);
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
close: () => {
|
|
72
|
+
for (const subscription of Object.values(client.subscriptions())) {
|
|
73
|
+
closeSubscription(client, subscription);
|
|
74
|
+
}
|
|
75
|
+
client.removeAllListeners();
|
|
76
|
+
client.disconnect();
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function closeSubscription(client, subscription) {
|
|
81
|
+
try {
|
|
82
|
+
subscription.unsubscribe();
|
|
83
|
+
subscription.removeAllListeners();
|
|
84
|
+
client.removeSubscription(subscription);
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
log_1.default.debug(`Failed to close realtime logs subscription: ${err.message}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -5,9 +5,10 @@ function uniqBy(list, getKey) {
|
|
|
5
5
|
const uniqueValues = new Set();
|
|
6
6
|
const result = [];
|
|
7
7
|
for (const i of list) {
|
|
8
|
-
|
|
8
|
+
const key = getKey(i);
|
|
9
|
+
if (!uniqueValues.has(key)) {
|
|
9
10
|
result.push(i);
|
|
10
|
-
uniqueValues.add(
|
|
11
|
+
uniqueValues.add(key);
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
14
|
return result;
|
package/build/worker/upload.d.ts
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import { HeadersInit, RequestInit, Response } from 'node-fetch';
|
|
2
2
|
import { AssetFileEntry } from './assets';
|
|
3
|
+
interface SharedRetryState {
|
|
4
|
+
hasSeenNetworkError: boolean;
|
|
5
|
+
hasWarned: boolean;
|
|
6
|
+
}
|
|
7
|
+
interface RetryState {
|
|
8
|
+
shared: SharedRetryState;
|
|
9
|
+
firstRetryAt?: number;
|
|
10
|
+
}
|
|
11
|
+
interface UploadRetryOptions {
|
|
12
|
+
totalRequests?: number;
|
|
13
|
+
state?: RetryState;
|
|
14
|
+
deadlineAt?: number;
|
|
15
|
+
}
|
|
3
16
|
export type UploadPayload = {
|
|
4
17
|
filePath: string;
|
|
5
18
|
} | {
|
|
@@ -18,7 +31,7 @@ export interface UploadResult {
|
|
|
18
31
|
response: Response;
|
|
19
32
|
}
|
|
20
33
|
type OnProgressUpdateCallback = (progress: number) => void;
|
|
21
|
-
export declare function uploadAsync(init: UploadRequestInit, payload: UploadPayload, onProgressUpdate?: OnProgressUpdateCallback): Promise<UploadResult>;
|
|
34
|
+
export declare function uploadAsync(init: UploadRequestInit, payload: UploadPayload, onProgressUpdate?: OnProgressUpdateCallback, retryOptions?: UploadRetryOptions, networkMode?: boolean): Promise<UploadResult>;
|
|
22
35
|
export declare function callUploadApiAsync(url: string | URL, init?: RequestInit): Promise<unknown>;
|
|
23
36
|
export interface UploadPending {
|
|
24
37
|
payload: UploadPayload;
|
package/build/worker/upload.js
CHANGED
|
@@ -13,9 +13,34 @@ const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
|
13
13
|
const node_os_1 = tslib_1.__importDefault(require("node:os"));
|
|
14
14
|
const node_stream_1 = require("node:stream");
|
|
15
15
|
const promise_retry_1 = tslib_1.__importDefault(require("promise-retry"));
|
|
16
|
+
const log_1 = tslib_1.__importDefault(require("../log"));
|
|
16
17
|
const multipart_1 = require("./utils/multipart");
|
|
17
18
|
const MAX_CONCURRENCY = Math.min(10, Math.max(node_os_1.default.availableParallelism() * 2, 20));
|
|
18
|
-
const
|
|
19
|
+
const MAX_RETRY_WARNING_DELAY_MS = 30_000;
|
|
20
|
+
const UPLOAD_RETRY_LIMITS = { retries: 4, maxTimeout: 5_000, maxRetryTime: 20_000 };
|
|
21
|
+
const API_RETRY_LIMITS = { retries: 6, maxTimeout: 5_000, maxRetryTime: 30_000 };
|
|
22
|
+
const getRetryScale = (totalRequests) => Math.min(1, Math.log10(Math.max(1, totalRequests)) / 3);
|
|
23
|
+
const getErrorMessage = (error) => error instanceof Error ? error.message : String(error);
|
|
24
|
+
const getRetryOptions = (limits, totalRequests, networkMode) => {
|
|
25
|
+
const scale = getRetryScale(totalRequests);
|
|
26
|
+
return {
|
|
27
|
+
retries: Math.round(limits.retries * (1 + scale)) + (networkMode ? 2 : 0),
|
|
28
|
+
factor: 2,
|
|
29
|
+
minTimeout: 1_000,
|
|
30
|
+
maxTimeout: Math.round(limits.maxTimeout * (1 + scale)),
|
|
31
|
+
maxRetryTime: Math.round(limits.maxRetryTime * (1 + scale)),
|
|
32
|
+
randomize: true,
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
const getRetryWarningDelay = (maxRetryTime) => Math.min(MAX_RETRY_WARNING_DELAY_MS, Math.round(maxRetryTime / 2));
|
|
36
|
+
const retryWithWarning = (retry, error, attempt, { state, warningDelayMs, subject }) => {
|
|
37
|
+
state.firstRetryAt ??= Date.now();
|
|
38
|
+
if (!state.shared.hasWarned && attempt > 1 && Date.now() - state.firstRetryAt >= warningDelayMs) {
|
|
39
|
+
state.shared.hasWarned = true;
|
|
40
|
+
log_1.default.warn(`${subject} encountered an error but is still retrying: ${getErrorMessage(error)}`);
|
|
41
|
+
}
|
|
42
|
+
return retry(error);
|
|
43
|
+
};
|
|
19
44
|
let sharedAgent;
|
|
20
45
|
const getAgent = () => {
|
|
21
46
|
if (sharedAgent) {
|
|
@@ -34,8 +59,20 @@ const getAgent = () => {
|
|
|
34
59
|
}));
|
|
35
60
|
}
|
|
36
61
|
};
|
|
37
|
-
async function uploadAsync(init, payload, onProgressUpdate) {
|
|
38
|
-
|
|
62
|
+
async function uploadAsync(init, payload, onProgressUpdate, retryOptions = {}, networkMode = retryOptions.state?.shared.hasSeenNetworkError ?? false) {
|
|
63
|
+
const state = retryOptions.state ?? {
|
|
64
|
+
shared: { hasSeenNetworkError: false, hasWarned: false },
|
|
65
|
+
};
|
|
66
|
+
const retryOptionsForAttempts = getRetryOptions(UPLOAD_RETRY_LIMITS, retryOptions.totalRequests ?? 1, networkMode);
|
|
67
|
+
const warningDelayMs = getRetryWarningDelay(retryOptionsForAttempts.maxRetryTime);
|
|
68
|
+
const deadlineAt = retryOptions.deadlineAt ?? Date.now() + retryOptionsForAttempts.maxRetryTime;
|
|
69
|
+
retryOptionsForAttempts.maxRetryTime = Math.max(0, deadlineAt - Date.now());
|
|
70
|
+
const warningContext = {
|
|
71
|
+
state,
|
|
72
|
+
warningDelayMs,
|
|
73
|
+
subject: 'The upload',
|
|
74
|
+
};
|
|
75
|
+
return await (0, promise_retry_1.default)(async (retry, attempt) => {
|
|
39
76
|
if (onProgressUpdate) {
|
|
40
77
|
onProgressUpdate(0);
|
|
41
78
|
}
|
|
@@ -83,7 +120,14 @@ async function uploadAsync(init, payload, onProgressUpdate) {
|
|
|
83
120
|
});
|
|
84
121
|
}
|
|
85
122
|
catch (error) {
|
|
86
|
-
|
|
123
|
+
if (init.signal?.aborted) {
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
if (!networkMode) {
|
|
127
|
+
state.shared.hasSeenNetworkError = true;
|
|
128
|
+
return await uploadAsync(init, payload, onProgressUpdate, { ...retryOptions, state, deadlineAt }, true);
|
|
129
|
+
}
|
|
130
|
+
return retryWithWarning(retry, error, attempt, warningContext);
|
|
87
131
|
}
|
|
88
132
|
const getErrorMessageAsync = async () => {
|
|
89
133
|
const rayId = response.headers.get('cf-ray');
|
|
@@ -108,7 +152,7 @@ async function uploadAsync(init, payload, onProgressUpdate) {
|
|
|
108
152
|
response.status === 409 ||
|
|
109
153
|
response.status === 429 ||
|
|
110
154
|
(response.status >= 500 && response.status <= 599)) {
|
|
111
|
-
return retry
|
|
155
|
+
return retryWithWarning(retry, new Error(await getErrorMessageAsync()), attempt, warningContext);
|
|
112
156
|
}
|
|
113
157
|
else if (response.status === 413) {
|
|
114
158
|
const message = `${errorPrefix}: File size exceeded the upload limit`;
|
|
@@ -120,18 +164,24 @@ async function uploadAsync(init, payload, onProgressUpdate) {
|
|
|
120
164
|
else if (onProgressUpdate) {
|
|
121
165
|
onProgressUpdate(1);
|
|
122
166
|
}
|
|
167
|
+
state.shared.hasSeenNetworkError = false;
|
|
123
168
|
return {
|
|
124
169
|
payload,
|
|
125
170
|
response,
|
|
126
171
|
};
|
|
127
|
-
},
|
|
128
|
-
retries: MAX_RETRIES,
|
|
129
|
-
minTimeout: 50,
|
|
130
|
-
randomize: false,
|
|
131
|
-
});
|
|
172
|
+
}, retryOptionsForAttempts);
|
|
132
173
|
}
|
|
133
|
-
async function
|
|
134
|
-
|
|
174
|
+
async function callUploadApiWithRetryAsync(url, init, networkMode = false, state = { shared: { hasSeenNetworkError: false, hasWarned: false } }, deadlineAt) {
|
|
175
|
+
const retryOptions = getRetryOptions(API_RETRY_LIMITS, 1, networkMode);
|
|
176
|
+
const warningDelayMs = getRetryWarningDelay(retryOptions.maxRetryTime);
|
|
177
|
+
const retryDeadlineAt = deadlineAt ?? Date.now() + retryOptions.maxRetryTime;
|
|
178
|
+
retryOptions.maxRetryTime = Math.max(0, retryDeadlineAt - Date.now());
|
|
179
|
+
const warningContext = {
|
|
180
|
+
state,
|
|
181
|
+
warningDelayMs,
|
|
182
|
+
subject: 'The deployment',
|
|
183
|
+
};
|
|
184
|
+
return await (0, promise_retry_1.default)(async (retry, attempt) => {
|
|
135
185
|
let response;
|
|
136
186
|
try {
|
|
137
187
|
response = await (0, node_fetch_1.default)(url, {
|
|
@@ -140,22 +190,33 @@ async function callUploadApiAsync(url, init) {
|
|
|
140
190
|
});
|
|
141
191
|
}
|
|
142
192
|
catch (error) {
|
|
143
|
-
|
|
193
|
+
if (init?.signal?.aborted) {
|
|
194
|
+
throw error;
|
|
195
|
+
}
|
|
196
|
+
if (!networkMode) {
|
|
197
|
+
state.shared.hasSeenNetworkError = true;
|
|
198
|
+
return await callUploadApiWithRetryAsync(url, init, true, state, retryDeadlineAt);
|
|
199
|
+
}
|
|
200
|
+
return retryWithWarning(retry, error, attempt, warningContext);
|
|
144
201
|
}
|
|
145
202
|
if (response.status >= 500 && response.status <= 599) {
|
|
146
|
-
retry
|
|
203
|
+
retryWithWarning(retry, new Error(`Deployment failed: ${response.statusText}`), attempt, warningContext);
|
|
147
204
|
}
|
|
148
205
|
try {
|
|
149
206
|
return await response.json();
|
|
150
207
|
}
|
|
151
208
|
catch (error) {
|
|
152
|
-
retry
|
|
209
|
+
return retryWithWarning(retry, error, attempt, warningContext);
|
|
153
210
|
}
|
|
154
|
-
});
|
|
211
|
+
}, retryOptions);
|
|
212
|
+
}
|
|
213
|
+
async function callUploadApiAsync(url, init) {
|
|
214
|
+
return await callUploadApiWithRetryAsync(url, init);
|
|
155
215
|
}
|
|
156
216
|
async function* batchUploadAsync(init, payloads, onProgressUpdate) {
|
|
157
217
|
const progressTracker = new Array(payloads.length).fill(0);
|
|
158
218
|
const controller = new AbortController();
|
|
219
|
+
const sharedRetryState = { hasSeenNetworkError: false, hasWarned: false };
|
|
159
220
|
const queue = new Set();
|
|
160
221
|
const initWithSignal = { ...init, signal: controller.signal };
|
|
161
222
|
const getProgressValue = () => {
|
|
@@ -178,7 +239,10 @@ async function* batchUploadAsync(init, payloads, onProgressUpdate) {
|
|
|
178
239
|
progressTracker[currentIndex] = progress;
|
|
179
240
|
sendProgressUpdate();
|
|
180
241
|
});
|
|
181
|
-
const uploadPromise = uploadAsync(initWithSignal, payload, onChildProgressUpdate
|
|
242
|
+
const uploadPromise = uploadAsync(initWithSignal, payload, onChildProgressUpdate, {
|
|
243
|
+
totalRequests: payloads.length,
|
|
244
|
+
state: { shared: sharedRetryState },
|
|
245
|
+
}).then(result => {
|
|
182
246
|
queue.delete(uploadPromise);
|
|
183
247
|
progressTracker[currentIndex] = 1;
|
|
184
248
|
return result;
|