Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion interface/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
wrap/
.polywrap/
.polywrap/
build/
Binary file removed interface/build/wrap.info
Binary file not shown.
12 changes: 7 additions & 5 deletions interface/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"name": "@polywrap/concurrent-interface",
"description": "Concurrent interface",
"private": true,
"name": "@polywrap/concurrency-interface",
"description": "Polywrap Concurrency Interface",
"version": "0.10.0",
"scripts": {
"build": "npx polywrap build",
"deploy": "npx polywrap deploy -o ./deployment.json"
"deploy": "npx polywrap deploy -o deployment.json"
},
"devDependencies": {
"polywrap": "0.10.2"
"polywrap": "0.10.3"
},
"publishConfig": {
"access": "public"
}
}
14 changes: 8 additions & 6 deletions interface/polywrap.deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
format: 0.1.0
stages:
format: 0.2.0
jobs:
ipfs_deploy:
package: ipfs
uri: fs/./build
config:
gatewayUri: https://ipfs.wrappers.io
steps:
- name: ipfs_deploy
package: ipfs
uri: fs/./build
config:
gatewayUri: https://ipfs.wrappers.io
158 changes: 135 additions & 23 deletions interface/polywrap.graphql
Original file line number Diff line number Diff line change
@@ -1,37 +1,149 @@
"""
Indicates the current status of a task.
"""
enum TaskStatus {
PENDING # applicable when running in pool
RUNNING
COMPLETED
CANCELLED # applicable when threads/processes are used
FAILED
"""
Task is scheduled but not yet running. This status is typically applicable when tasks are queued to run in a pool.
"""
PENDING
"""
Task is currently executing.
"""
RUNNING
"""
Task execution has been paused.
"""
SUSPENDED
"""
Task has completed execution successfully.
"""
COMPLETED
"""
Task execution has been cancelled before completion. This status is typically applicable when threads or processes are used and are aborted before they complete.
"""
CANCELLED
"""
Task has failed to execute successfully.
"""
FAILED
}

"""
Defines when the result() function should return, based on the status of the tasks.
"""
enum ReturnWhen {
FIRST_COMPLETED, # return the first task that completes or fails
ANY_COMPLETED, # return any task that completes or returns array of all the errors
ALL_COMPLETED, # return result of all the tasks or failures
"""
Return as soon as the first task completes or fails.
"""
FIRST_COMPLETED
"""
Return any task that completes or return an array of all the errors if tasks fail.
"""
ANY_COMPLETED
"""
Wait for all tasks to complete or fail and return the result.
"""
ALL_COMPLETED
}

type Task {
uri: String!
method: String!
args: Bytes!
"""
Indicates the priority level of a task. This helps determine the order in which tasks are executed.
"""
enum Priority {
"""
Low priority. Tasks with this priority will be executed after tasks with higher priority.
"""
LOW
"""
Medium priority. This is the default priority for tasks.
"""
MEDIUM
"""
High priority. Tasks with this priority will be executed before tasks with lower priority.
"""
HIGH
}

type TaskResult {
taskId: Int!
result: Bytes
error: String
status: TaskStatus!
"""
Defines the structure and parameters of a task.
"""
type Task {
"""
The URI of the wrapper to invoke.
"""
uri: String!
"""
The method to invoke.
"""
method: String!
"""
The arguments to be passed to the method upon invocation, serialized in MessagePack format.
"""
args: Bytes!
"""
The priority level of the task. This helps determine the order in which the task will be executed. Defaults to Priority.MEDIUM if not specified.
"""
priority: Priority

Choose a reason for hiding this comment

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

How can we enforce this? What are some use cases of this?

"""
A list of task IDs that the task depends on. The task will not be executed until all its dependencies have completed.
"""
dependsOn: [Int!]
"""
The maximum number of workers that should be used to execute this task. If not specified, the system will determine the optimal number of workers.
"""
max_workers: Int

Choose a reason for hiding this comment

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

It might be beneficial to have max_workers available both as an argument and within the environment variables instead of either one.

}

type Env {
max_workers: Int
"""
Defines the structure of the result returned by a task.
"""
type TaskResult {
"""
The unique ID assigned to the task.
"""
taskId: Int!
"""
The result produced by the task, serialized in MessagePack format.
"""
result: Bytes
"""
An error message, present only if the task failed to execute successfully.
"""
error: String
"""
The current status of the task.
"""
status: TaskStatus!
}

type Module {
result(taskIds: [Int!]!, returnWhen: ReturnWhen!): [TaskResult!]!
status(taskIds: [Int!]!): [TaskStatus!]!
schedule(tasks: [Task!]!): [Int!]! # returns taskIds
abort(taskIds: [String!]!): [Boolean!]!
"""
Retrieve the results of one or more scheduled tasks. The 'returnWhen' parameter determines when the function should return.
"""
result(taskIds: [Int!]!, returnWhen: ReturnWhen!): [TaskResult!]!

"""
Retrieve the current status of one or more scheduled tasks.
"""
status(taskIds: [Int!]!): [TaskStatus!]!

"""
Schedule one or more tasks for execution. Returns an array of unique task IDs, one for each scheduled task.
"""
schedule(tasks: [Task!]!): [Int!]!

"""
Send a request to abort one or more scheduled tasks. Returns an array of booleans indicating whether each task was successfully aborted.
"""
abort(taskIds: [Int!]!): [Boolean!]!

"""
Pause execution of one or more scheduled tasks. Returns an array of booleans indicating whether each task was successfully paused.
"""
pause(taskIds: [Int!]!): [Boolean!]!

"""
Resume execution of one or more paused tasks. Returns an array of booleans indicating whether each task was successfully resumed.
"""
resume(taskIds: [Int!]!): [Boolean!]!
}
3 changes: 1 addition & 2 deletions interface/polywrap.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
format: 0.3.0
project:
name: concurrent-interface
name: concurrency-interface
type: interface
source:
schema: ./polywrap.graphql
resources: ./resources
99 changes: 67 additions & 32 deletions interface/resources/README.md
Original file line number Diff line number Diff line change
@@ -1,63 +1,98 @@
# Concurrent Wrapper Interface
# Datetime Wrapper Interface

| Version | URI | WRAP Version |
|-|-|-|
| 1.0.0 | [`wrap://ens/wraps.eth:concurrent@1.0.0`](https://wrappers.io/v/ens/wraps.eth:concurrent@1.0.0) | 0.1 |

## Description

The concurrent interface provides a common concurrency interface that can be shared across various concurrency implementations, like Threads, Processes and even language specific primitives like JavaScript Promises.
| 1.0.0 | [`wrap://ens/wraps.eth:concurrency@1.0.0`](https://wrappers.io/v/ens/wraps.eth:concurrency@1.0.0) | 0.1 |

## Interface
```graphql
enum TaskStatus {
PENDING # applicable when running in pool
RUNNING
COMPLETED
CANCELLED # applicable when threads/processes are used
FAILED
# Task is scheduled but not yet running. Applicable when running in pool
PENDING
# Task is executing
RUNNING
# Task is paused
SUSPENDED
# Task has completed execution
COMPLETED
# Task has been aborted. Applicable when threads/processes are used
CANCELLED
# Task failed to execute
FAILED
}

enum ReturnWhen {
FIRST_COMPLETED, # return the first task that completes or fails
ANY_COMPLETED, # return any task that completes or returns array of all the errors
ALL_COMPLETED, # return result of all the tasks or failures
# return the first task that completes or fails
FIRST_COMPLETED
# return any task that completes or returns array of all the errors
ANY_COMPLETED
# return result of all the tasks or failures
ALL_COMPLETED
}

type Task {
uri: String!
method: String!
args: Bytes!
# Priority helps determine the order in which tasks will be run
enum Priority {
LOW
MEDIUM
HIGH
}

type TaskResult {
taskId: Int!
result: Bytes
error: String
status: TaskStatus!
type Task {
# Wrap URI to invoke
uri: String!
# Method name
method: String!
# Invocation arguments, serialized in MessagePack format
args: Bytes!
# Priority helps determine the order in which tasks will be run. Defaults to Priority.MEDIUM.
priority: Priority
# Task will not run until dependent tasks have completed
dependsOn: [Int!]
# The maximum number of workers that should be used to execute this task
max_workers: Int
}

type Env {
max_workers: Int
type TaskResult {
# Unique ID of task
taskId: Int!
# Invocation result, serialized in MessagePack format
result: Bytes
# Error message that is present if task failed, and null otherwise
error: String
# The current status of the task
status: TaskStatus!
}

type Module {
result(taskIds: [Int!]!, returnWhen: ReturnWhen!): [TaskResult!]!
status(taskIds: [Int!]!): [TaskStatus!]!
schedule(tasks: [Task!]!): [Int!]! # returns taskIds
abort(taskIds: [String!]!): [Boolean!]!
# Get the result of one or more scheduled tasks
result(taskIds: [Int!]!, returnWhen: ReturnWhen!): [TaskResult!]!

# Get the status of one or more scheduled tasks
status(taskIds: [Int!]!): [TaskStatus!]!

# Schedule one or more tasks; returns the Task ID of each scheduled task
schedule(tasks: [Task!]!): [Int!]!

# Request to abort one or more scheduled tasks
abort(taskIds: [Int!]!): [Boolean!]!

# Pause execution of one or more scheduled tasks
pause(taskIds: [Int!]!): [Boolean!]!

# Resume execution of one or more paused tasks
resume(taskIds: [Int!]!): [Boolean!]!
}
```

## Usage
```graphql
#import * from "ens/wraps.eth:concurrent@1.0.0"
#import * from "ens/wraps.eth:concurrency@1.0.0"
```

And implement the interface methods within your programming language of choice.

## Source Code
[Link](https://github.com/polywrap/concurrent)
[Link](https://github.com/polywrap/std/concurrency)

## Known Implementations
[Link](https://github.com/polywrap/concurrent/tree/main/implementations)
[Link](https://github.com/polywrap/concurrency/tree/master/implementations)
Loading