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

Add task cancellation hooks into the build definition. #1242

Merged
merged 6 commits into from
Apr 9, 2014

Conversation

jsuereth
Copy link
Member

@jsuereth jsuereth commented Apr 8, 2014

This enables configurable strategies for non-CLI clients to register for all task evaluations.

  • Mini TaskCancel library
  • Deprecate existing EvaluateConfig case class in favor of EvaluateTaskConfig trait (which is
    easier to evolve in BC way)
  • Move all methods taking EvaluateConfig into methods taking EvaluateTaskConfig.
  • Add hooks in build for cancel handlers
  • Expose hooks in Signal library for non-ARM usage

Review by @eed3si9n & @havocp cc @skyluc

* Create a new EvaluateTaskConfig which gives us a bit more freedom
  over changign config options to EvaluateTask in the future.
* Create adapted from old EvaluateTask to new EvaluateTask
* Add hooks into signals class to register/remote  a signal listener
  directly, rather than in an "arm" block.
* Create TaskEvaluationCancelHandler to control the strategy of
  who/whom can cancel (sbt-server vs. sbt-terminal).
* Create a null-object for the "can't cancel" scenario so the
  code path is exactly the same.

This commit does not wire settings into the build yet, nor does it
fix the config extractio methods.
* Expose new EvaluateTaskConfig throughout all the APIs
* Create a key for cancellation configuration
* Add default values for cancellation in GlobalPlugin
* Create a test to ensure that cancellation can cancel tasks.
* Deprecate all the existing mechanisms of evaluating tasks which
  use the EvaluateConfig API.
/** cancels whatever this points at. */
def cancel(): Unit
}
/** A handler for registering/remmoving listeners that allow you to cancel tasks. */
Copy link
Contributor

Choose a reason for hiding this comment

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

this comment seems confusing. "An implementation of cancellation for a particular task" ? "handle cancellation for a task evaluation" ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess in fact it's "Implementations of this trait determine what will trigger cancel() on the TaskCancel provided to the start() method. This may be a signal, or a protocol request, or nothing."

@havocp
Copy link
Contributor

havocp commented Apr 8, 2014

If I understand this correctly, the problem this solves is that we can call cancel() in response to a protocol request instead of a signal. It looks fine for that, my only thought is that I found the doc comments sort of unclear.

@jsuereth
Copy link
Member Author

jsuereth commented Apr 8, 2014

@havocp Yep, that's what it does. I've fixed the documentation comments as suggested.

* [[TaskEvalautionCancelHandler]] which is responsible for calling `cancel()` when
* appropriate.
*/
trait TaskCancel {
Copy link
Member

Choose a reason for hiding this comment

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

If this represents anything that can be canceled, why not call it CanCancel instead of including the word Task?

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 did call it CanCancel first. I'm not sure this is aimed to be a generic "cancellable" API, I think I want to tie it to the TaskEngine, but calling it TaskEngine also felt wrong.

Should I update the docs to be nicer with regard to that?

Copy link
Member

Choose a reason for hiding this comment

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

What's wrong with a generic cancelable API? Settings are like generic setting API.

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 don't really have enough use-cases/design ideas right now to fully genericize. We'd end up with a half-a$$ed implementation of a generic API. I'd rather not have to maintain such a thing until we know what a cancellation API should look like.

Copy link
Member

Choose a reason for hiding this comment

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

If not CanCancel I'd go for CancellableTask so it's a noun phrase.

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, it's not a CancellableTask, but a CancellableTaskEngine....

I can modify to that if you think the name is better.

taskCancelStrategy := { state: State =>
if(cancelable.value) TaskCancellationStrategy.Signal
else TaskCancellationStrategy.Null
},
Copy link
Member

Choose a reason for hiding this comment

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

When Defaults.scala starts to make sense, you know we are on to something.

Copy link
Member Author

Choose a reason for hiding this comment

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

:) That was the goal.

* Rename TaskCancel to RunningTaskEngine for clarity
* Explicitly pass a state value in TaskCancellationStrategy
* Update hooks to be immutable/safe.
@eed3si9n
Copy link
Member

eed3si9n commented Apr 9, 2014

LGTM

@jsuereth
Copy link
Member Author

jsuereth commented Apr 9, 2014

TravisCI failure seems to be transient timeout death.

eed3si9n added a commit that referenced this pull request Apr 9, 2014
Add task cancellation hooks into the build definition.
@eed3si9n eed3si9n merged commit 78d2aab into 0.13 Apr 9, 2014
@jsuereth jsuereth deleted the wip/cancel-task-hooks branch April 9, 2014 16:55
jvican pushed a commit to scalacenter/sbt that referenced this pull request May 23, 2017
Add task cancellation hooks into the build definition.
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

5 participants