Skip to content

Proposal Context object #279

@johnynek

Description

@johnynek

Right now, methods that read or write have to take an implicit FlowDef and Mode. I propose that we define a Context object like:

class Context {
  def flowDef: FlowDef
  def mode: Mode
  def args: Args
}

This allows us to extend features to include things like (tracing, see: https://github.com/etsy/scalding/pull/4) without having to rewrite existing methods.

Also, this fixes an old issue around getting the mode implicitly. Now, we statically set one mode in Mode.mode. This breaks thread-safety and prevent parallel testing. With this approach, the Context can be created in the Tool, and passed into the Job.

This is a pretty big change.

For most functions that don't explicitly pass implicit variables, changing from (implicit fd: FlowDef, mode: Mode) to (implicit ctx: Context) won't be an issue, but all jobs have a single Args parameter input. How to pass Context instead?

My work around, which is ugly, would be to make Context a subclass of Args. Then in job, add a method:

implicit def context: Context = {
  args match {
    case ctx: Context => ctx
    case _ => sys.error("Given an Args that is not an instance of Context")
  }
}

The "right" way to go would be to just change Job to accept Context. If we do the right way, we should probably write a script of some kind that can automatically convert source code to the new format with a minimum of pain.

I invite a design discussion here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions