-
-
Notifications
You must be signed in to change notification settings - Fork 585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug job id return in gitlab host connector #1604
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je pense qu'il faut refactorer un peu l'algo, je t'ai mis qques pistes pour l'améliorer
let i = 0 | ||
setTimeout (() => { | ||
while (jobs[0].ref !== tag && i<20) { | ||
jobs = this.callApi(session, `api/v4/projects/${websiteId}/jobs`, 'GET') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although there's a condition to limit the loop to 20 iterations, the loop does not include any delay or await between iterations. It will make many calls to callApi for each timeout
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, the setTimeout is tune with a delay and I have mesured the mean number f call that are between 0 and 5 cycles. What I am missing ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't wait for an answer (await)
so jobs will be a promise, not the actual result
and it will run 100 times without waiting for a result
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to verify my comprehension, this should work better ?
setTimeout (async () => { while (jobs[0].ref !== tag && i<20) { jobs = await this.callApi(session,
api/v4/projects/${websiteId}/jobs, 'GET') i++ } }, 100)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no because the setTimeout will not wait that the async finishes, you have multiple calls in parallel
check my proposal of algorithm, this will do a call, wait for the response, wait a little, loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check my proposal of algorithm, this will do a call, wait for the response, wait a little, loop
your algo will do: wait a little, start a call but don't get the result and don't wait, loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry for my lack of skills in async js field. I will try again !
const jobs = await this.callApi(session, `api/v4/projects/${websiteId}/jobs`, 'GET') | ||
return `${projectUrl}/-/jobs/${jobs[0].id}` | ||
async getGitlabJobLogsUrl(session: GitlabSession, websiteId: WebsiteId, job: PublicationJobData, { startJob, jobSuccess, jobError }: JobManager, projectUrl: string, tag): Promise<string> { | ||
let jobs = await this.callApi(session, `api/v4/projects/${websiteId}/jobs`, 'GET') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't make a first call then many other ones
I suggest :
- Do
- await get the tag (callApi)
- if the tag is the expected one return it
- await TIME_BEFORE_RETRY - see the way to do this (first solution of this article)
- While elapsed time < TIMEOUT
EDIT: I changed it a little
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Don't make a first call then many other ones"
I don't understand, I need to get the first time the jobs in order to read its jobs.ref containing the current tag ? otherwise I don't know how to initialize the while loop ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"await TIME_BEFORE_RETRY ", I thought that setTimeout do the same ? https://www.freecodecamp.org/news/javascript-settimeout-how-to-set-a-timer-in-javascript-or-sleep-for-n-seconds/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"await get the tag (callApi)
await TIME_BEFORE_RETRY - see the way to do this (first solution of this article)
While elapsed time < TIMEOUT and the tag is not the expected one"
I beleived I'm doing exactly this algo ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Don't make a first call then many other ones"
I don't understand, I need to get the first time the jobs in order to read its jobs.ref containing the current tag ? otherwise I don't know how to initialize the while loop ?
use a do while instead of a while
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"await TIME_BEFORE_RETRY ", I thought that setTimeout do the same ? https://www.freecodecamp.org/news/javascript-settimeout-how-to-set-a-timer-in-javascript-or-sleep-for-n-seconds/
the setTimeout takes a callback, and given the complexity of this algorithm you should use await and no callback, it will make it obvious my other feedback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for your time to explain to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will change with do while, thanks for advices
const jobs = await this.callApi(session, `api/v4/projects/${websiteId}/jobs`, 'GET') | ||
if (jobs[0].ref === tag) {return `${projectUrl}/-/jobs/${jobs[0].id}`} | ||
await setTimeout(5) | ||
} while (i<19) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it would be clearer to compare execution time instead of the number of loops
use Date.now() to get the current time
i++ | ||
const jobs = await this.callApi(session, `api/v4/projects/${websiteId}/jobs`, 'GET') | ||
if (jobs[0].ref === tag) {return `${projectUrl}/-/jobs/${jobs[0].id}`} | ||
await setTimeout(5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5
here is in milliseconds, maybe you should give it more time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could but I have tested and it works between 1 and less than 10 * 5 ms ? I could put 50 ms if it's better ? else ?
const jobs = await this.callApi(session, `api/v4/projects/${websiteId}/jobs`, 'GET') | ||
if (jobs[0].ref === tag) {return `${projectUrl}/-/jobs/${jobs[0].id}`} | ||
await setTimeout(5000) | ||
} while ((Date.now() - t0) < 15000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
laaaast thing, you may want to set this timeout as an option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Well done!!
* gitlab hosting connector with good current job id return * gitlab hosting connector with good current job id return 2 * gitlab hosting connector with good current job id return v3 * with setTimout problem corrected * with setTimout problem corrected 2 * with setTimout problem corrected 3 * with setTimout problem corrected 3 * with setTimout problem corrected 3 * with setTimout problem corrected 4 * with setTimout problem corrected 4 * with setTimout problem corrected 5 * with setTimout problem corrected 5 * with setTimout problem corrected 6 * with timer in variables --------- Co-authored-by: Ubuntu <ubuntu@ov-bddc60.infomaniak.ch>
* Added plugin * Update package.json * The publication dialog now displays a message to suggest the user to verify their GitLab account when needed + Loading bar visual improvement * Update grapesjs-plugins.scss * Update GitlabHostingConnector.ts * Added a target=_blank on the link * Update package.json * Bug job id return in gitlab host connector (#1604) * gitlab hosting connector with good current job id return * gitlab hosting connector with good current job id return 2 * gitlab hosting connector with good current job id return v3 * with setTimout problem corrected * with setTimout problem corrected 2 * with setTimout problem corrected 3 * with setTimout problem corrected 3 * with setTimout problem corrected 3 * with setTimout problem corrected 4 * with setTimout problem corrected 4 * with setTimout problem corrected 5 * with setTimout problem corrected 5 * with setTimout problem corrected 6 * with timer in variables --------- Co-authored-by: Ubuntu <ubuntu@ov-bddc60.infomaniak.ch> * The publication dialog now displays a message to suggest the user to verify their GitLab account when needed + Loading bar visual improvement * Merged changes * Fixed bad merge --------- Co-authored-by: oliviermgx <73127173+oliviermgx@users.noreply.github.com> Co-authored-by: Ubuntu <ubuntu@ov-bddc60.infomaniak.ch>
No description provided.