-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from tabkram/engine-decorators
- Loading branch information
Showing
16 changed files
with
846 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# EngineTask | ||
|
||
The `EngineTask` class represents an abstract task with a reference to the `ExecutionEngine`. It serves as a base class for integrating execution engine capabilities into other classes. | ||
|
||
## @engine Decorator | ||
|
||
The `@engine` decorator enhances a class with execution engine capabilities. It takes a configuration object as an argument, allowing you to customize the behavior of the associated engine. | ||
|
||
### Usage | ||
|
||
```typescript | ||
@engine({ id: "uniqueEngineId" }) | ||
class MyClass extends EngineTask { | ||
// Class implementation | ||
} | ||
``` | ||
|
||
#### Explanation | ||
|
||
The `@engine` decorator is applied to a class to inject execution engine capabilities. The configuration object passed as an argument provides a unique identifier (`id`) for the associated engine. This allows multiple classes to use different engines, each with its own configuration. | ||
|
||
## @run Decorator | ||
|
||
The `@run` decorator enables tracing for decorated methods. It takes trace options as an optional argument, allowing you to fine-tune the tracing behavior. | ||
|
||
### Usage | ||
|
||
```typescript | ||
class MyClass extends EngineTask { | ||
@run() | ||
myMethod1(param: string) { | ||
// Method implementation | ||
} | ||
|
||
@run() | ||
async myMethod2(param: string) { | ||
// Async method implementation | ||
} | ||
``` | ||
#### Explanation | ||
The `@run` decorator is applied to methods within a class to enable tracing for their executions. The optional trace options allow you to customize the tracing behavior for specific methods. For example, you can configure whether a method should be traced asynchronously or set additional options for the trace. | ||
This section provides a detailed explanation of how to use the `@engine` and `@run` decorators along with the `EngineTask` class. By understanding the purpose and usage of these decorators, you can effectively integrate execution engine features and tracing into your TypeScript classes, tailoring them to the specific requirements of your project. Adjust the import statements and decorator parameters based on your actual implementation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
[ | ||
{ | ||
"data": { | ||
"id": "bound myMethod1_1702207617652_13a5a286-3150-4950-b67a-8e03a797b770", | ||
"label": "bound myMethod1", | ||
"inputs": [ | ||
"param1" | ||
], | ||
"outputs": "result1 for param1", | ||
"startTime": "2023-12-10T11:26:57.652Z", | ||
"endTime": "2023-12-10T11:26:57.653Z", | ||
"duration": 0.40799999237060547, | ||
"elapsedTime": "0.408 ms", | ||
"parallel": false, | ||
"abstract": false, | ||
"createTime": "2023-12-10T11:26:57.653Z" | ||
}, | ||
"group": "nodes" | ||
}, | ||
{ | ||
"data": { | ||
"id": "bound myMethod2_1702207617653_daeb25cd-1822-48d8-9744-a460bfe9f82f", | ||
"label": "bound myMethod2", | ||
"inputs": [ | ||
"param2" | ||
], | ||
"outputs": "result2 for param2", | ||
"startTime": "2023-12-10T11:26:57.653Z", | ||
"endTime": "2023-12-10T11:26:57.653Z", | ||
"duration": 0.2049999237060547, | ||
"elapsedTime": "0.205 ms", | ||
"parallel": false, | ||
"abstract": false, | ||
"createTime": "2023-12-10T11:26:57.653Z" | ||
}, | ||
"group": "nodes" | ||
}, | ||
{ | ||
"data": { | ||
"id": "bound myMethod1_1702207617652_13a5a286-3150-4950-b67a-8e03a797b770->bound myMethod2_1702207617653_daeb25cd-1822-48d8-9744-a460bfe9f82f", | ||
"source": "bound myMethod1_1702207617652_13a5a286-3150-4950-b67a-8e03a797b770", | ||
"target": "bound myMethod2_1702207617653_daeb25cd-1822-48d8-9744-a460bfe9f82f", | ||
"parallel": false | ||
}, | ||
"group": "edges" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { engine, EngineTask, run } from '../src'; | ||
import { writeTrace } from './common/writeTrace'; | ||
|
||
@engine({ id: 'uniqueEngineId' }) | ||
class MyClass extends EngineTask { | ||
@run() | ||
myMethod1(param: string) { | ||
return `result1 for ${param}`; | ||
} | ||
|
||
@run() | ||
async myMethod2(param: string) { | ||
return `result2 for ${param}`; | ||
} | ||
} | ||
|
||
export async function generate() { | ||
const myInstance = new MyClass(); | ||
myInstance.myMethod1('param1'); | ||
await myInstance.myMethod2('param2'); | ||
|
||
// Retrieve the trace | ||
const trace = myInstance.engine.getTrace(); | ||
const jsonString = JSON.stringify(trace, null, 2); | ||
writeTrace(jsonString); | ||
} | ||
|
||
generate().then(); |
Oops, something went wrong.
10dfdac
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage report
Test suite run success
32 tests passing in 5 suites.
Report generated by 🧪jest coverage report action from 10dfdac