Skip to content
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

Merged
merged 14 commits into from
Jun 19, 2024
Merged

Conversation

oliviermgx
Copy link
Contributor

No description provided.

Copy link
Member

@lexoyo lexoyo left a 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

src/ts/plugins/server/GitlabHostingConnector.ts Outdated Show resolved Hide resolved
let i = 0
setTimeout (() => {
while (jobs[0].ref !== tag && i<20) {
jobs = this.callApi(session, `api/v4/projects/${websiteId}/jobs`, 'GET')
Copy link
Member

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

Copy link
Contributor Author

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 ?

Copy link
Member

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

Copy link
Contributor Author

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)

Copy link
Member

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

Copy link
Member

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

Copy link
Contributor Author

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')
Copy link
Member

@lexoyo lexoyo Jun 7, 2024

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 :

  1. Do
  2. await get the tag (callApi)
  3. if the tag is the expected one return it
  4. await TIME_BEFORE_RETRY - see the way to do this (first solution of this article)
  5. While elapsed time < TIMEOUT

EDIT: I changed it a little

Copy link
Contributor Author

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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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 ?

Copy link
Member

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

Copy link
Member

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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

@oliviermgx oliviermgx requested a review from lexoyo June 12, 2024 12:28
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)
Copy link
Member

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)
Copy link
Member

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?

Copy link
Contributor Author

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)
Copy link
Member

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?

@oliviermgx oliviermgx requested a review from lexoyo June 16, 2024 17:12
Copy link
Member

@lexoyo lexoyo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Well done!!

@lexoyo lexoyo merged commit a2cae53 into silexlabs:dev Jun 19, 2024
2 checks passed
SuperDelphi pushed a commit to SuperDelphi/Silex that referenced this pull request Jun 19, 2024
* 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>
lexoyo pushed a commit that referenced this pull request Jun 19, 2024
* 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>
@oliviermgx oliviermgx deleted the bug_job_id branch August 13, 2024 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants