Skip to content
This repository has been archived by the owner on Nov 14, 2019. It is now read-only.

Commit

Permalink
Merge pull request #101 from mesg-foundation/update-proto
Browse files Browse the repository at this point in the history
Update proto
  • Loading branch information
antho1404 authored Jun 7, 2019
2 parents ee2e532 + da8cae6 commit b01c2ef
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 33 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ mesg.executeTask({
inputData: JSON.stringify(__INPUT_DATA__),
executionTags: [__ASSOCIATE_TAG__] // optional
}).then((execution) => {
console.log('task in progress with execution id:', execution.executionID)
console.log('task in progress with execution:', execution.executionHash)
}).catch((err) => {
console.error('task execution failed with err:', err.message)
})
Expand Down Expand Up @@ -214,8 +214,8 @@ interface ListenResultRequest {

```ts
interface ResultData {
// Execution id of the task that result belongs to.
executionID: string
// Hash of the execution.
executionHash: string

// Task key of the result.
taskKey: string
Expand Down Expand Up @@ -255,8 +255,8 @@ interface ExecuteTaskRequest {

```ts
interface ExecuteTaskReply {
// Unique id for the execution.
executionID: string
// Hash of the execution.
executionHash: string
}
```

Expand Down Expand Up @@ -284,7 +284,7 @@ mesg.api.ExecuteTask({
console.error(error)
return
}
console.log('task in progress with execution id:', reply.executionID)
console.log('task in progress with execution:', reply.executionHash)
})
```

Expand Down
4 changes: 2 additions & 2 deletions src/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ interface EventData {
}

interface ResultData {
executionID: string
executionHash: string
taskKey: string
outputData: string
executionTags: string[]
Expand All @@ -90,7 +90,7 @@ interface ExecuteTaskRequest {
}

interface ExecuteTaskReply {
executionID: string
executionHash: string
}

export default Application;
Expand Down
8 changes: 4 additions & 4 deletions src/application/application_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ test('executeTask() should resolve promise with reply', (t) => {
t.plan(1);
const client = new testClient;
const application = new Application({ client });
const reply: ExecuteTaskReply = { executionID: '1' }
const reply: ExecuteTaskReply = { executionHash: '1' }
const stub = sinon.stub(client, 'ExecuteTask').callsFake((req, cb) => cb(undefined, reply))
application.executeTask({
serviceID: '2',
taskKey: '3',
inputData: '4'
}).then((reply) => t.equal(reply.executionID, '1') )
}).then((reply) => t.equal(reply.executionHash, '1') )
stub.restore()
});

Expand Down Expand Up @@ -137,8 +137,8 @@ test('executeTaskAndWaitResult() should resolve and cancel result stream on firs
const application = new Application({ client });
const spy = sinon.spy(client.resultStream, 'cancel')
application.executeTaskAndWaitResult({ serviceID: '2', taskKey: '3', inputData: '4' })
.then((result) => t.equal(result.executionID, '2'))
client.resultStream.emit('data', { executionID: '2' })
.then((result) => t.equal(result.executionHash, '2'))
client.resultStream.emit('data', { executionHash: '2' })
t.ok(spy.calledOnce)
spy.restore()
});
Expand Down
12 changes: 6 additions & 6 deletions src/protobuf/coreapi/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import "protobuf/definition/service.proto";
package api;
option go_package = "github.com/mesg-foundation/core/protobuf/coreapi";

// This is the primary API to interact with MESG Core functionalities.
// It can be consumed by any applications or tools that you'd like to interact with MESG Core.
// This is the primary API to interact with MESG Engine functionalities.
// It can be consumed by any applications or tools that you'd like to interact with MESG Engine.
// It is actually used by the MESG CLI and MESG Application libraries.
//
// This API is only accessible through [gRPC](https://grpc.io/).
Expand Down Expand Up @@ -100,15 +100,15 @@ message ListenResultRequest {
// **Example**
// ```json
// {
// "executionID": "__EXECUTION_ID__",
// "executionHash": "__EXECUTION_HASH__",
// "taskKey": "__TASK_KEY__",
// "outputData": "{\"foo\":\"bar\"}",
// "executionTags": ["executionX", "test"],
// "error": "error from the execution if something went wrong",
// }
// ```
message ResultData {
string executionID = 1; // The unique identifier of the execution.
string executionHash = 1; // The unique identifier of the execution.
string taskKey = 2; // The key of the executed task.
string outputData = 4; // The output's data from the returned task, encoded in JSON.
repeated string executionTags = 5; // The list of tags associated with the execution.
Expand Down Expand Up @@ -138,11 +138,11 @@ message ExecuteTaskRequest {
// **Example**
// ```json
// {
// "executionID": "__EXECUTION_ID__"
// "executionHash": "__EXECUTION_HASH__"
// }
// ```
message ExecuteTaskReply {
string executionID = 1; // The unique identifier of the execution.
string executionHash = 1; // The unique identifier of the execution.
}

// The request's data for the `StartService` API.
Expand Down
1 change: 1 addition & 0 deletions src/protobuf/definition/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ message Service {
repeated Event events = 6; // The list of events this service can emit.
repeated Dependency dependencies = 7; // The container dependencies this service requires.
string repository = 9; // Service's repository url.
string source = 13; // The hash id of service's source code on IPFS.
}

// Events are emitted by the service whenever the service wants.
Expand Down
16 changes: 8 additions & 8 deletions src/protobuf/serviceapi/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ syntax = "proto3";
package api;
option go_package = "github.com/mesg-foundation/core/protobuf/serviceapi";

// This is the API for MESG Services to interact with MESG Core.
// This is the API for MESG Services to interact with MESG Engine.
// It is to be consumed only by MESG Services.
// It provides all necessary functions that MESG Services need in order to interact with MESG Core.
// It provides all necessary functions that MESG Services need in order to interact with MESG Engine.
//
// This API is only accessible through [gRPC](https://grpc.io/).
//
Expand Down Expand Up @@ -60,35 +60,35 @@ message ListenTaskRequest {

// The data received from the stream of the `ListenTask` API.
// The data will be received over time as long as the stream is open.
// The `executionID` value must be kept and sent with the result when calling the [`SubmitResult` API](#submitresult).
// The `executionHash` value must be kept and sent with the result when calling the [`SubmitResult` API](#submitresult).
//
// **Example:**
// ```json
// {
// "executionID": "__EXECUTION_ID__",
// "executionHash": "__EXECUTION_HASH__",
// "taskKey": "__TASK_KEY__",
// "inputData": "{\"inputX\":\"Hello world!\",\"inputY\":true}"
// }
// ```
message TaskData {
string executionID = 1; // The unique identifier of the execution. Must be kept and sent with the result when calling the [`SubmitResult` API](#submitresult).
string executionHash = 1; // The unique identifier of the execution. Must be kept and sent with the result when calling the [`SubmitResult` API](#submitresult).
string taskKey = 2; // The key from the task to execute as defined in the [service file](../guide/service/service-file.md).
string inputData = 3; // The task's input encoded in JSON as defined in the [service file](../guide/service/service-file.md).
}

// The request's data for the `SubmitResult` API.
// The data must contain the `executionID` of the executed task received from the stream of [`ListenTask` API](#listentask).
// The data must contain the `executionHash` of the executed task received from the stream of [`ListenTask` API](#listentask).
//
// **Example:**
// ```json
// {
// "executionID": "__EXECUTION_ID__",
// "executionHash": "__EXECUTION_HASH__",
// "outputData": "{\"foo\":\"super result\",\"bar\":true}"
// "error": "{\"message\":\"some error\"}"
// }
// ```
message SubmitResultRequest {
string executionID = 1; // The `executionID` received from the [`ListenTask` stream](#listentask).
string executionHash = 1; // The `executionHash` received from the [`ListenTask` stream](#listentask).
oneof result {
string outputData = 3; // The result's data encoded in JSON as defined in the [service file](../guide/service/service-file.md).
string error = 4; // The error message.
Expand Down
8 changes: 4 additions & 4 deletions src/service/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Service {
})
}

private async handleTaskData({ executionID, taskKey, inputData }) {
private async handleTaskData({ executionHash, taskKey, inputData }) {
const callback = this.tasks[taskKey];
if (!callback) {
throw new Error(`Task ${taskKey} is not defined in your services`);
Expand All @@ -53,10 +53,10 @@ class Service {
try {
const outputs = await callback(data);
const outputData = JSON.stringify(outputs);
return this.submitResult({ executionID, outputData });
return this.submitResult({ executionHash, outputData });
} catch (err) {
const error = err.message;
return this.submitResult({ executionID, error });
return this.submitResult({ executionHash, error });
}
}

Expand Down Expand Up @@ -97,7 +97,7 @@ interface SubmitResultReply {
}

interface TaskData {
executionID: string
executionHash: string
taskKey: string
inputData: string
}
Expand Down
6 changes: 3 additions & 3 deletions src/service/service_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ test('listenTask() should listen for tasks', function (t) {

test('listenTask() should handle tasks and submit result', async function (t) {
t.plan(4);
const executionID = 'id';
const executionHash = 'hash';
const inputData = {input: 'data'};
const outputData = {output: 'data'};
const client = new testClient;
Expand All @@ -106,11 +106,11 @@ test('listenTask() should handle tasks and submit result', async function (t) {
t.deepEqual(inputData, inputs);
return outputData
}});
t.doesNotThrow(() => stream.emit('data', { executionID, taskKey: 'task1', inputData: JSON.stringify(inputData) }));
t.doesNotThrow(() => stream.emit('data', { executionHash, taskKey: 'task1', inputData: JSON.stringify(inputData) }));
await setTimeout(()=>{}, 0)
const args = spy.getCall(0).args[0];
spy.restore();
t.equal(args.executionID, executionID);
t.equal(args.executionHash, executionHash);
t.equal(args.outputData, JSON.stringify(outputData));
});

Expand Down

0 comments on commit b01c2ef

Please sign in to comment.