Skip to content

Commit e34dfaf

Browse files
committed
fix: publish articles one by one instead of all at the same time
1 parent 9704e91 commit e34dfaf

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/dev-to-git.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
Repository,
1212
UpdateStatus,
1313
} from './dev-to-git.interface';
14-
import { formatArticlePublishedStatuses, logBuilder, Logger } from './helpers';
14+
import { Logger, formatArticlePublishedStatuses, logBuilder } from './helpers';
1515

1616
export const DEFAULT_CONFIG_PATH: string = './dev-to-git.json';
1717

@@ -105,15 +105,18 @@ export class DevToGit {
105105
}));
106106
}
107107

108-
public publishArticles(): Promise<ArticlePublishedStatus[]> {
108+
public async publishArticles(): Promise<ArticlePublishedStatus[]> {
109109
const articles = this.readConfigFile();
110110

111-
return Promise.all(
112-
articles.map(articleConf => {
113-
const article = new Article(articleConf, this.configuration.devToToken);
114-
return article.publishArticle();
115-
}),
116-
);
111+
const articlePublishedStatuses = []
112+
113+
// instead of using Promise.all we use a for with await
114+
// to run the updates one by one to avoid hammering dev.to API
115+
// and have more risks of being rate limited
116+
for (const articleConf of articles) {
117+
const article = new Article(articleConf, this.configuration.devToToken);
118+
articlePublishedStatuses.push(await article.publishArticle());
119+
}
117120
}
118121
}
119122

0 commit comments

Comments
 (0)