Skip to content

Commit 846be4b

Browse files
authored
fix(plugins/languages): improved timeout messages (lowlighter#1004) [skip ci]
1 parent e3fcd61 commit 846be4b

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

source/plugins/languages/analyzers.mjs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@ import linguist from "linguist-js"
33

44
/**Indepth analyzer */
55
export async function indepth({login, data, imports, repositories, gpg}, {skipped, categories, timeout}) {
6-
return new Promise(async (solve, reject) => {
6+
return new Promise(async solve => {
7+
//Results
8+
const results = {partial:false, total:0, lines:{}, stats:{}, colors:{}, commits:0, files:0, missed:{lines:0, bytes:0, commits:0}, verified:{signature:0}}
9+
710
//Timeout
811
if (Number.isFinite(timeout)) {
912
console.debug(`metrics/compute/${login}/plugins > languages > timeout set to ${timeout}m`)
10-
setTimeout(() => reject(`Reached maximum execution time of ${timeout}m for analysis`), timeout * 60 * 1000)
13+
setTimeout(() => {
14+
results.partial = true
15+
console.debug(`metrics/compute/${login}/plugins > languages > reached maximum execution time of ${timeout}m for analysis`)
16+
solve(results)
17+
}, timeout * 60 * 1000)
1118
}
1219

1320
//GPG keys imports
@@ -35,8 +42,11 @@ export async function indepth({login, data, imports, repositories, gpg}, {skippe
3542
}
3643

3744
//Compute repositories stats from fetched repositories
38-
const results = {total:0, lines:{}, stats:{}, colors:{}, commits:0, files:0, missed:{lines:0, bytes:0, commits:0}, verified:{signature:0}}
3945
for (const repository of repositories) {
46+
//Early break
47+
if (results.partial)
48+
break
49+
4050
//Skip repository if asked
4151
if ((skipped.includes(repository.name.toLocaleLowerCase())) || (skipped.includes(`${repository.owner.login}/${repository.name}`.toLocaleLowerCase()))) {
4252
console.debug(`metrics/compute/${login}/plugins > languages > skipped repository ${repository.owner.login}/${repository.name}`)
@@ -77,16 +87,24 @@ export async function indepth({login, data, imports, repositories, gpg}, {skippe
7787

7888
/**Recent languages activity */
7989
export async function recent({login, data, imports, rest, account}, {skipped = [], categories, days = 0, load = 0, tempdir = "recent", timeout}) {
80-
return new Promise(async (solve, reject) => {
90+
return new Promise(async solve => {
91+
//Results
92+
const results = {partial:false, total:0, lines:{}, stats:{}, colors:{}, commits:0, files:0, missed:{lines:0, bytes:0, commits:0}, days}
93+
8194
//Timeout
8295
if (Number.isFinite(timeout)) {
8396
console.debug(`metrics/compute/${login}/plugins > languages > timeout set to ${timeout}m`)
84-
setTimeout(() => reject(`Reached maximum execution time of ${timeout}m for analysis`), timeout * 60 * 1000)
97+
setTimeout(() => {
98+
results.partial = true
99+
console.debug(`metrics/compute/${login}/plugins > languages > reached maximum execution time of ${timeout}m for analysis`)
100+
solve(results)
101+
return
102+
}, timeout * 60 * 1000)
85103
}
86104

87105
//Get user recent activity
88106
console.debug(`metrics/compute/${login}/plugins > languages > querying api`)
89-
const commits = [], pages = Math.ceil(load / 100), results = {total:0, lines:{}, stats:{}, colors:{}, commits:0, files:0, missed:{lines:0, bytes:0, commits:0}, days}
107+
const commits = [], pages = Math.ceil(load / 100)
90108
try {
91109
for (let page = 1; page <= pages; page++) {
92110
console.debug(`metrics/compute/${login}/plugins > languages > loading page ${page}`)

source/templates/classic/partials/languages.ejs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@
8484
</div>
8585
</div>
8686
<% } %>
87+
<% if ({"most-used":plugins.languages.partial, "recently-used":plugins.languages["stats.recent"]?.partial}[section]) { %>
88+
<div class="row footnote warning">
89+
<div class="field">
90+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M8.22 1.754a.25.25 0 00-.44 0L1.698 13.132a.25.25 0 00.22.368h12.164a.25.25 0 00.22-.368L8.22 1.754zm-1.763-.707c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0114.082 15H1.918a1.75 1.75 0 01-1.543-2.575L6.457 1.047zM9 11a1 1 0 11-2 0 1 1 0 012 0zm-.25-5.25a.75.75 0 00-1.5 0v2.5a.75.75 0 001.5 0v-2.5z"></path></svg>
91+
Reached maximum execution time for analysis, partial results are displayed
92+
</div>
93+
</div>
94+
<% } %>
8795
<% } %>
8896
</section>
8997
<% } %>

source/templates/classic/style.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,12 @@
276276
justify-content: flex-end;
277277
font-size: 12px;
278278
}
279+
.footnote.warning {
280+
color: #D79533;
281+
}
282+
.footnote.warning svg {
283+
fill: #D79533;
284+
}
279285

280286
/* Follow-up */
281287
.followup.legend {

0 commit comments

Comments
 (0)