Skip to content

Feature: ability to persist context's between task runs #15

@ericallam

Description

@ericallam

For the use case I am trying to use engine.js for It would be very helpful to be able to setup a context and then have multiple tasks run against that context. The use case (for me) is this:

A user submits code that somehow changes the context (let's say, incrementing a counter), does a console.log, and returns a certain value. I want to be able to verify three things:

  • The correct value was returned
  • The correct value was logged
  • The counter was incremented in the context

Currently, I can only verify the first two in the above list. I think to give the most flexibility and to limit the changes to the scope and feature set of engine.js, we could allow multiple tasks to run against a single context. The api might look something like this (assuming the api changes discussed in pull request 14:

var context = client.createContext("(function(locals) { var count=0; return { incr: function(){ count+=1; return count }}})");

var task = client.createTask();
task.setContext(context);
task.setLocals({});
task.setCode("incr()");

client.run(task, function(err, result, logs){
  console.log(result); // 1

  var verifyTask = client.createTask();
  verifyTask.setContext(context);
  verifyTask.setLocals({});
  verifyTask.setCode("incr()");

  client.run(verifyTask, function(err, result, logs){
    console.log(result); // 2
  });
});

Please let me know if this even sounds doable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions