feat: remove concurrency from the long tasks
This commit is contained in:
parent
813420427f
commit
00fd1512c5
|
|
@ -11,7 +11,8 @@ const mapper = {} as Record<string, Bottleneck>;
|
|||
export const concurrency = async <T>(
|
||||
identifier: string,
|
||||
maxConcurrent = 1,
|
||||
func: (...args: any[]) => Promise<T>
|
||||
func: (...args: any[]) => Promise<T>,
|
||||
ignoreConcurrency = false
|
||||
) => {
|
||||
const strippedIdentifier = identifier.toLowerCase().split('-')[0];
|
||||
mapper[strippedIdentifier] ??= new Bottleneck({
|
||||
|
|
@ -23,6 +24,9 @@ export const concurrency = async <T>(
|
|||
});
|
||||
let load: T;
|
||||
try {
|
||||
if (ignoreConcurrency) {
|
||||
return await func();
|
||||
}
|
||||
load = await mapper[strippedIdentifier].schedule<T>(
|
||||
{ expiration: 600000 },
|
||||
async () => {
|
||||
|
|
|
|||
|
|
@ -68,12 +68,14 @@ export abstract class SocialAbstract {
|
|||
url: string,
|
||||
options: RequestInit = {},
|
||||
identifier = '',
|
||||
totalRetries = 0
|
||||
totalRetries = 0,
|
||||
ignoreConcurrency = false
|
||||
): Promise<Response> {
|
||||
const request = await concurrency(
|
||||
this.identifier,
|
||||
this.maxConcurrentJob,
|
||||
() => fetch(url, options)
|
||||
() => fetch(url, options),
|
||||
ignoreConcurrency
|
||||
);
|
||||
|
||||
if (request.status === 200 || request.status === 201) {
|
||||
|
|
|
|||
|
|
@ -498,7 +498,11 @@ export class InstagramProvider
|
|||
while (status === 'IN_PROGRESS') {
|
||||
const { status_code } = await (
|
||||
await this.fetch(
|
||||
`https://${type}/v20.0/${photoId}?access_token=${accessToken}&fields=status_code`
|
||||
`https://${type}/v20.0/${photoId}?access_token=${accessToken}&fields=status_code`,
|
||||
undefined,
|
||||
'',
|
||||
0,
|
||||
true,
|
||||
)
|
||||
).json();
|
||||
await timer(10000);
|
||||
|
|
@ -558,7 +562,11 @@ export class InstagramProvider
|
|||
while (status === 'IN_PROGRESS') {
|
||||
const { status_code } = await (
|
||||
await this.fetch(
|
||||
`https://${type}/v20.0/${containerId}?fields=status_code&access_token=${accessToken}`
|
||||
`https://${type}/v20.0/${containerId}?fields=status_code&access_token=${accessToken}`,
|
||||
undefined,
|
||||
'',
|
||||
0,
|
||||
true
|
||||
)
|
||||
).json();
|
||||
await timer(10000);
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ export class PinterestProvider
|
|||
value: string;
|
||||
}
|
||||
| undefined {
|
||||
|
||||
if (body.indexOf('cover_image_url or cover_image_content_type') > -1) {
|
||||
return {
|
||||
type: 'bad-body' as const,
|
||||
|
|
@ -212,12 +211,18 @@ export class PinterestProvider
|
|||
let statusCode = '';
|
||||
while (statusCode !== 'succeeded') {
|
||||
const mediafile = await (
|
||||
await this.fetch('https://api.pinterest.com/v5/media/' + media_id, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
await this.fetch(
|
||||
'https://api.pinterest.com/v5/media/' + media_id,
|
||||
{
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
},
|
||||
},
|
||||
})
|
||||
'',
|
||||
0,
|
||||
true
|
||||
)
|
||||
).json();
|
||||
|
||||
await timer(30000);
|
||||
|
|
|
|||
|
|
@ -375,7 +375,10 @@ export class TiktokProvider extends SocialAbstract implements SocialProvider {
|
|||
body: JSON.stringify({
|
||||
publish_id: publishId,
|
||||
}),
|
||||
}
|
||||
},
|
||||
'',
|
||||
0,
|
||||
true
|
||||
)
|
||||
).json();
|
||||
|
||||
|
|
@ -399,11 +402,11 @@ export class TiktokProvider extends SocialAbstract implements SocialProvider {
|
|||
'titok-error-upload',
|
||||
JSON.stringify(post),
|
||||
Buffer.from(JSON.stringify(post)),
|
||||
handleError?.value || '',
|
||||
handleError?.value || ''
|
||||
);
|
||||
}
|
||||
|
||||
await timer(3000);
|
||||
await timer(10000);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -496,7 +499,11 @@ export class TiktokProvider extends SocialAbstract implements SocialProvider {
|
|||
photo_cover_index: 0,
|
||||
photo_images: firstPost.media?.map((p) => p.path),
|
||||
},
|
||||
post_mode: firstPost?.settings?.content_posting_method === 'DIRECT_POST' ? 'DIRECT_POST' : 'MEDIA_UPLOAD',
|
||||
post_mode:
|
||||
firstPost?.settings?.content_posting_method ===
|
||||
'DIRECT_POST'
|
||||
? 'DIRECT_POST'
|
||||
: 'MEDIA_UPLOAD',
|
||||
media_type: 'PHOTO',
|
||||
}),
|
||||
}),
|
||||
|
|
|
|||
Loading…
Reference in New Issue