Skip to content

Commit 4b15fc9

Browse files
committed
Retry upload on failure + Add more build commands
1 parent 8456216 commit 4b15fc9

File tree

1 file changed

+51
-28
lines changed

1 file changed

+51
-28
lines changed

‎main.js‎

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,39 +1021,59 @@ function uploadToTelegram (bot, task, build, sdkVariant, abiVariant, onDone) {
10211021
}
10221022
};
10231023

1024-
bot.sendDocument(build.serviceChatId, fs.createReadStream(files.apkFile.path), {
1025-
reply_to_message_id: build.serviceMessageId,
1026-
caption: getBuildCaption(build, sdkVariant, abiVariant),
1027-
parse_mode: 'HTML'
1028-
}, {
1029-
contentType: APK_MIME_TYPE
1030-
}).then((message) => {
1031-
files.apkFile.remote_id = message.document.file_id;
1032-
modifyNativeDebugSymbolsArchive(files.nativeDebugSymbolsFile.path).then((nativeDebugSymbolsPath) => {
1033-
const nativeDebugSymbolsStream = fs.createReadStream(nativeDebugSymbolsPath);
1034-
bot.sendDocument(build.serviceChatId, nativeDebugSymbolsStream, {
1035-
reply_to_message_id: message.message_id
1024+
const maxUploadAttemptCount = 5;
1025+
1026+
const onMappingUploaded = (mappingMessage) => {
1027+
onDone(0);
1028+
};
1029+
1030+
const onSymbolsUploaded = (symbolsMessage) => {
1031+
if (!files.mappingFile) { // Mapping file doesn't exist for builds made with --dontobfuscate option
1032+
onDone(0);
1033+
return;
1034+
}
1035+
attemptAction(maxUploadAttemptCount, (accept, reject) => {
1036+
bot.sendDocument(build.serviceChatId, fs.createReadStream(files.mappingFile.path), {
1037+
reply_to_message_id: symbolsMessage.message_id
10361038
}, {
1037-
contentType: 'application/zip'
1038-
}).then((symbolsMessage) => {
1039-
if (!files.mappingFile) { // Mapping file doesn't exist for builds made with --dontobfuscate option
1040-
onDone(0);
1041-
return;
1042-
}
1043-
bot.sendDocument(build.serviceChatId, fs.createReadStream(files.mappingFile.path), {
1044-
reply_to_message_id: message.message_id
1039+
contentType: 'text/plain'
1040+
}).then(accept).catch(reject);
1041+
}, (e, attemptNo) => {
1042+
console.log('[RETRY]', 'Trying again to upload mapping file to Telegram, attemptNo:', attemptNo, e);
1043+
}).then(onMappingUploaded).catch((e) => {
1044+
failWithError('Cannot upload mapping file', e);
1045+
})
1046+
};
1047+
1048+
const onApkUploaded = (apkMessage) => {
1049+
files.apkFile.remote_id = apkMessage.document.file_id;
1050+
modifyNativeDebugSymbolsArchive(files.nativeDebugSymbolsFile.path).then((nativeDebugSymbolsPath) => {
1051+
attemptAction(maxUploadAttemptCount, (accept, reject) => {
1052+
const nativeDebugSymbolsStream = fs.createReadStream(nativeDebugSymbolsPath);
1053+
bot.sendDocument(build.serviceChatId, nativeDebugSymbolsStream, {
1054+
reply_to_message_id: apkMessage.message_id
10451055
}, {
1046-
contentType: 'text/plain'
1047-
}).then((mappingMessage) => {
1048-
onDone(0);
1049-
}).catch((e) => {
1050-
failWithError('Cannot upload mapping file', e);
1051-
})
1052-
}).catch((e) => {
1056+
contentType: 'application/zip'
1057+
}).then(accept).catch(reject);
1058+
}, (e, attemptNo) => {
1059+
console.log('[RETRY]', 'Trying again to upload native-debug-symbols.zip to Telegram, attemptNo:', attemptNo, e);
1060+
}).then(onSymbolsUploaded).catch((e) => {
10531061
failWithError('Cannot upload native-debug-symbols.zip', e);
10541062
});
10551063
});
1056-
}).catch((e) => {
1064+
};
1065+
1066+
attemptAction(maxUploadAttemptCount, (accept, reject) => {
1067+
bot.sendDocument(build.serviceChatId, fs.createReadStream(files.apkFile.path), {
1068+
reply_to_message_id: build.serviceMessageId,
1069+
caption: getBuildCaption(build, sdkVariant, abiVariant),
1070+
parse_mode: 'HTML'
1071+
}, {
1072+
contentType: APK_MIME_TYPE
1073+
}).then(accept).catch(reject);
1074+
}, (e, attemptNo) => {
1075+
console.log('[RETRY]', 'Trying again to upload APK to Telegram, attemptNo:', attemptNo, e);
1076+
}).then(onApkUploaded).catch((e) => {
10571077
failWithError('Cannot upload telegram file', e);
10581078
});
10591079

@@ -2260,14 +2280,17 @@ function processPrivateCommand (botId, bot, msg, command, commandArgsRaw) {
22602280
case '/build_arm64':
22612281
case '/build_x86':
22622282
case '/build_x64':
2283+
case '/build_latest':
22632284
case '/build_latestArm32':
22642285
case '/build_latestArm64':
22652286
case '/build_latestX86':
22662287
case '/build_latestX64':
2288+
case '/build_lollipop':
22672289
case '/build_lollipopArm32':
22682290
case '/build_lollipopArm64':
22692291
case '/build_lollipopX86':
22702292
case '/build_lollipopX64':
2293+
case '/build_legacy':
22712294
case '/build_legacyArm32':
22722295
case '/build_legacyX86':
22732296
case '/build_huawei':

0 commit comments

Comments
 (0)