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

Avoid job duplication by Github webhooks #34

Merged
merged 4 commits into from Jul 13, 2018

Conversation

tallysmartins
Copy link
Member

Signed-off-by: Tallys Martins tallysmartins@gmail.com

@coveralls
Copy link

coveralls commented Jun 28, 2018

Coverage Status

Coverage increased (+0.8%) to 78.571% when pulling e7d0a84 on tallysmartins:webhooks_improvements into 87507a3 on elixir-bench:master.

Copy link
Member

@PragTob PragTob left a comment

Choose a reason for hiding this comment

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

Looking good, a couple of questions from me towards the implementation :)

@@ -63,6 +73,18 @@ defmodule ElixirBench.Benchmarks do
Repo.all(Job)
end

def get_or_create_job(repo, attrs) do
Copy link
Member

Choose a reason for hiding this comment

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

I like introducing this abstraction! 👍

Copy link
Member

Choose a reason for hiding this comment

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

Speaking of abstraction I like - I think this deserves unit tests. Like the 2 major cases, but also what happens if we get 2 commits with the same sha but from different repositories (see my argument above)

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, I added test cases to cover this... in the future if we care about the branch name and not just the repo and commit sha the tests will cover this scenario and fail

@@ -51,6 +51,16 @@ defmodule ElixirBench.Benchmarks do
Repo.fetch(where(Job, uuid: ^uuid))
end

def fetch_running_job_by_reference(branch_name, commit_sha) do
Copy link
Member

Choose a reason for hiding this comment

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

do we need this to be public atm?

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

Job
|> last
|> Job.unfinished()
|> where(branch_name: ^branch_name, commit_sha: ^commit_sha)
Copy link
Member

Choose a reason for hiding this comment

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

where does the reference come from? I wonder if it's an appropriate name for it.

I also think we can just drop the branch name - commit shas shouldn't duplicate so we're save there. This seems to be missing any scoping by repository or so which we should rather introduce imo

Copy link
Member Author

Choose a reason for hiding this comment

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

reference I meant branch name and commit... but you are right, this is not the best name. I will also add a check for the repo as I said in my previous comment.

About skipping the branch name, I agree that it's possible and simpler. But I like the idea of separate builds for each branch to maintain the history and not just respond with the previous results.. But then we think about evolving this feature.

Copy link
Member Author

Choose a reason for hiding this comment

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

added the scope and changed to a more sigificative name

query =
Job
|> last
|> Job.unfinished()
Copy link
Member

Choose a reason for hiding this comment

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

why do we scope by unfinished? If it's the same sha for the same repo, I don't care if it's still running or not I don't think we should run it again unless a user explicitly requests this and we don't have this feature yet :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, in fact knowing if there is an existent job for a branch and commit should be enough, regardless if its running or finished. And I missed the repo part here.. it must be checked.

Copy link
Member Author

Choose a reason for hiding this comment

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

make sense... :)

@tallysmartins tallysmartins force-pushed the webhooks_improvements branch 4 times, most recently from bfde612 to 8257b78 Compare July 5, 2018 02:13
Copy link
Member

@PragTob PragTob left a comment

Choose a reason for hiding this comment

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

💃

Copy link
Member

@PragTob PragTob left a comment

Choose a reason for hiding this comment

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

ok foudna small thing

|> Job.unfinished()
|> where(branch_name: ^branch_name, commit_sha: ^commit_sha)
|> Job.filter_by_repo(repo.id)
|> where(commit_sha: ^commit_sha)
Copy link
Member

Choose a reason for hiding this comment

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

as we removed last won't this return multiple jobs now instead of just one? I think the code still works but it's confusing and we potentially do more than we should

Copy link
Member Author

Choose a reason for hiding this comment

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

you are right 💯... Repo.fetch will break if more than one Job is found... I changed a test case for that and put back the last

Copy link
Member Author

Choose a reason for hiding this comment

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

had to do a little change in tests as we just check jobs for a given repo and commit-sha, ignoring the branch name... so a test from WebhookController was failing

Copy link
Member

Choose a reason for hiding this comment

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

Repo.fetch wouldn't fail - Repo.one would fail :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Repo.fetch calls one in the end, see ElixirBench.Repo, I tested and it breaks 🕵️‍♂️

@tallysmartins tallysmartins force-pushed the webhooks_improvements branch 3 times, most recently from 5c6dd9f to 94c8ffe Compare July 11, 2018 14:37
- closes elixir-bench#29

Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
@PragTob PragTob merged commit 8b2b583 into elixir-bench:master Jul 13, 2018
@tallysmartins tallysmartins deleted the webhooks_improvements branch July 13, 2018 14:52
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.

None yet

3 participants