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

[WIP] Maintenance tasks in service #184

Closed

Conversation

wilbaker
Copy link
Member

@wilbaker wilbaker commented Oct 21, 2019

This is extremely WIP.

Resolves #112

TODOs:

  • Wire up maintenance scheduler on Windows
  • Add logging where appropriate
  • Update unit tests
  • Manually test changes on Windows and Mac
  • Move string computations to the constructor (or start/init method) where appropriate
  • Decide if maintenance tasks should only run for the logged in user on Windows (@derrickstolee and I agreed we can start with that approach)
  • Cleanup commit history

Follow up work (outside the scope of this PR):

Copy link
Contributor

@derrickstolee derrickstolee left a comment

Choose a reason for hiding this comment

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

I like the direction. Look at the GitMaintenanceQueue for directions for some of your TODOs.

Scalar.Service/MaintenanceTaskRunner.cs Outdated Show resolved Hide resolved
Scalar.Service/MaintenanceTaskRunner.cs Outdated Show resolved Hide resolved
Scalar.Service/MaintenanceTaskRunner.cs Outdated Show resolved Hide resolved
Scalar.Service/MaintenanceTaskRunner.cs Outdated Show resolved Hide resolved
Scalar.Service/RepoRegistry.cs Show resolved Hide resolved
string arguments =
$"asuser {sessionId} {this.scalarBinPath} maintenance \"{repoRoot}\" {task} --{ScalarConstants.VerbParameters.InternalUseOnly} {this.internalVerbJson}";

ProcessResult result = this.processLauncher.LaunchProcess(ExecutablePath, arguments, repoRoot);
Copy link
Contributor

Choose a reason for hiding this comment

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

To allow stopping, you'll want to create a Process object and store it as a private member. A Stop() method would then allow killing the process, creating an exception through the CallMaintenance() method.

Copy link
Member Author

Choose a reason for hiding this comment

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

@derrickstolee I plan to tackle this work as a follow up in #185

On the Mac side I think it should be pretty easy/straightforward as we're already using Process objects.

However, on the Windows side we have a big mess of native calls that ultimately end with a call to CreateProcessAsUser:

if (CreateProcessAsUser(

And now that I take another look we're not even waiting for that process to finish ☹️.

We might end up needing an interface that will internally use Process objects on Mac, and store PROCESS_INFORMATION on Windows (and then we can PInvoke to TerminateProcess to stop the process).

I will also do some research and see if there is a way to create a Process object for the process we're spawning on Windows. (GetProcessById might be an option, but we'd have to make sure we're not introducing any races if the process exits quickly).

Scalar.UnitTests/Service/Mac/MacServiceTests.cs Outdated Show resolved Hide resolved
@wilbaker wilbaker force-pushed the maintenance_tasks_in_service_wip branch from 501d0d2 to b7cf94b Compare October 22, 2019 20:51
@wilbaker wilbaker force-pushed the maintenance_tasks_in_service_wip branch from b7cf94b to 2dd5015 Compare October 22, 2019 20:56
@derrickstolee
Copy link
Contributor

I don't know why, but when I tried to build your tip commit, my build failed because ScalarService.Windows.cs referred to ScalarMountProcess. But when I use the pull request merge commit, everything builds fine.

Anyway, I'm installing on my laptop to get some extra checks that things are working.

@wilbaker
Copy link
Member Author

@derrickstolee

I don't know why, but when I tried to build your tip commit, my build failed

That might be on me, I did not have a chance to confirm the latest commit built on Windows before I headed out. I'll check that first thing when I get in tomorrow.

Also, I'm going to switch back to using a queue for the tasks (like we had before). The queue approach is battle tested, and it should be pretty easy to adjust the existing unit tests to work with a new queue. Plus as we discussed offline the edge case of "task taking too long" should not be a common occurrence.

@wilbaker
Copy link
Member Author

to get some extra checks that things are working

FYI - I haven't had a chance to do any manual tests yet and so things might not be working correctly yet.

My plan for tomorrow:

  • Switch back to queue and bring back its unit tests
  • Run some manual tests
  • Create a new non-WIP PR with a cleaned up branch

I plan to defer the work to have the functional tests not register when cloning (at least on Mac) until we make the changes to register in clone. If any of the maintenance tests get flaky before then we can have them unmount after cloning (if they aren't already).

@wilbaker
Copy link
Member Author

Closing out this PR, it will be replaced with a non-WIP PR.

@wilbaker wilbaker closed this Oct 23, 2019
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.

[Mount Removal] Perform maintenance jobs in the service rather than the mount process
2 participants