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

Keep track of PID of process running job #1

Merged
merged 6 commits into from
Jun 17, 2020
Merged

Conversation

roxelo
Copy link
Member

@roxelo roxelo commented Jun 12, 2020

This PR is still a work in progress, but so far this is what has been done:

  • Retrieve PID of process running job
  • Updated 2 git commands
    • Use -B instead of -b for creating new branch. (-B create the new branch only if the branch does not exists, otherwise it resets the branch
    • Added -p to the git fetch --all command, since @arora-aman mentioned it was better

Next to implement:

  • Figure out the best way to keep track of the process PID so we can easily terminate processes and implement it

Closes sexxi-goose/sexxi-sync#6

@roxelo roxelo added the wip work in progress label Jun 12, 2020
@roxelo roxelo requested a review from Azhng June 12, 2020 20:29
src/lib/config.rs Outdated Show resolved Hide resolved
src/lib/cmd.rs Outdated Show resolved Hide resolved
src/lib/cmd.rs Outdated Show resolved Hide resolved
src/lib/cmd.rs Outdated Show resolved Hide resolved
src/lib/cmd.rs Outdated Show resolved Hide resolved
@arora-aman
Copy link
Member

-p all gets information about branches that were deleted from the remote. However that doesn't mean that it will delete the local tracking branches.

I know someone wrote a utility to make that happen as well, but I don't remeber what that is called lol.

@roxelo
Copy link
Member Author

roxelo commented Jun 15, 2020

This kind of overlaps with sexxi-goose/sexxi-sync#7. I am considering maybe combining both tasks into one PR.

src/lib/cmd.rs Outdated Show resolved Hide resolved
src/lib/cmd.rs Outdated Show resolved Hide resolved
src/lib/job.rs Outdated Show resolved Hide resolved
@roxelo
Copy link
Member Author

roxelo commented Jun 16, 2020

If this looks good for tracking PID, I will go ahead and merge. This PR does terminate a job if the bot is removed and then re-added, but I decided I will just make a different PR for the conditions that require terminating a job.

@roxelo roxelo removed the wip work in progress label Jun 16, 2020
Copy link
Contributor

@Azhng Azhng left a comment

Choose a reason for hiding this comment

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

Left some nits for code style. But one thing that confuses me was why are we passing around curr_job ? It seems like it is used to detect if a job is already running for a given head_ref. I would much prefer we always go to JobRegistry as the source of truth to fetch the job information. Though that might require some modification of the JobRegistry to make it fast.

src/lib/config.rs Outdated Show resolved Hide resolved
src/lib/handler.rs Outdated Show resolved Hide resolved
src/lib/handler.rs Outdated Show resolved Hide resolved
src/lib/job.rs Outdated Show resolved Hide resolved
@roxelo
Copy link
Member Author

roxelo commented Jun 16, 2020

As I mentioned on Discord, JobRegistry by itself doesn't track the information we need. We could pass around JobRegistry but we would still need to know what the uuid of the running job is. That implies that we would be passing that around as well. I guess we could approach solving this by turning JobRegistry into a class/trait rather than a type, but before I go ahead and make those changes it would be best to both agree on what JobRegistry should look like for what we want it to do.

@roxelo
Copy link
Member Author

roxelo commented Jun 17, 2020

More testing to be performed tomorrow.
PID of running jobs are now being tracked in JobRegistry.
Conditions which should terminate a running jobs (sexxi-goose/sexxi-sync#5) will be added in a different PR for readability.

Copy link
Contributor

@Azhng Azhng left a comment

Choose a reason for hiding this comment

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

Awesome work! Just few comments!

src/lib/config.rs Show resolved Hide resolved
src/lib/job.rs Outdated Show resolved Hide resolved
have a deadlock. We want to update the JobDesc for the job with the PID of the
running process, but since we have the read lock, we can't acquire the write lock.

If we want to avoid having to request the read lock everytime we need it, we should
Copy link
Contributor

Choose a reason for hiding this comment

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

What about instead of a deep copy we just clone the Arc<RwLock<JobDesc>>, i know it's a bit boilerplate but we went through all these trouble just so we can avoid deep copy. I think current code works good so it's just my personal preference. Also implementing a macro can probably reduce the repetitive locking/unlocking.

@arora-aman thoughts ?

Copy link
Member

Choose a reason for hiding this comment

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

If we are doing a deep copy then we should probably do it earlier and write some other way of returning the status. But the way code is currently written it makes more sense to just clone the Arc instead of the cloning the underlying JobDesc

Copy link
Member Author

Choose a reason for hiding this comment

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

I am not sure if that really is needed.
Things to keep in mind, why make it more complicated right now when the job is only used for information so far, which should technically not be modified (except for PID, but let's ignore that for now).
Second, the JobRegistry is now being passed around as well as the running job uuid, so technically no need to pass the Arc<RwLock<JobDesc>> cause we can get it from the JobRegistry directly.

Copy link
Member

@arora-aman arora-aman Jun 17, 2020

Choose a reason for hiding this comment

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

if u clone the Arc it allows for you to modify the Desc without need to hold lock over the registry. However I don't think it is really need in our case.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not 100% faimilar with this codebase so I could be wrong, but start_build_job(job.clone(), ..) seems simpler, and would work.

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm no, cloning the Arc still require the read lock

Copy link
Member Author

@roxelo roxelo Jun 17, 2020

Choose a reason for hiding this comment

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

So I am not doing anything about this. Like the comment I left in the code stated, I don't think it is worth adding more concurrency complexity with the read lock when the data of JobDesc is not expected to change. A comment reflects this decision, if we want to change that we should be making a new issue.

src/lib/job.rs Show resolved Hide resolved
src/lib/cmd.rs Show resolved Hide resolved
src/lib/cmd.rs Outdated Show resolved Hide resolved
have a deadlock. We want to update the JobDesc for the job with the PID of the
running process, but since we have the read lock, we can't acquire the write lock.

If we want to avoid having to request the read lock everytime we need it, we should
Copy link
Member

Choose a reason for hiding this comment

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

If we are doing a deep copy then we should probably do it earlier and write some other way of returning the status. But the way code is currently written it makes more sense to just clone the Arc instead of the cloning the underlying JobDesc

Copy link
Contributor

@Azhng Azhng left a comment

Choose a reason for hiding this comment

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

Let's fix the locking issue in #2

@roxelo roxelo linked an issue Jun 17, 2020 that may be closed by this pull request
@roxelo roxelo merged commit 5c17ee1 into master Jun 17, 2020
@roxelo roxelo deleted the roxane/get-job-pid branch June 17, 2020 19:08
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.

Keep track of the PID of the process that's running the job
3 participants