Skip to content

Commit 4e2ee33

Browse files
Language updates
1 parent 48eb08e commit 4e2ee33

File tree

1 file changed

+42
-37
lines changed

1 file changed

+42
-37
lines changed

docs/source/custom_sockets.rst

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
Custom Sockets in Syncano
55
=========================
66

7-
``Syncano`` provides possibility of creating custom sockets. It means that there's a possibility
8-
to define a very specific endpoints in syncano application and use them as normal API calls.
9-
Currently custom sockets allow only one dependency - script. This mean that on the backend side
10-
each time the API is called - the script is executed and result from this script is returned as a result of the
7+
``Syncano`` gives its users an ability to create custom sockets. It means, that users can define
8+
a very specific endpoints in their Syncano application, and use them as other Syncano
9+
modules (Classes, Scripts, etc), using standard API calls.
10+
Currently, custom sockets allow only one dependency - Scripts. It means that on the backend side,
11+
each API call executes a Script and result of the execution, is returned as a result of the
1112
API call.
1213

1314
Creating a custom socket
@@ -19,16 +20,16 @@ To create a custom socket follow these steps::
1920
from syncano.models import CustomSocket, Endpoint, ScriptCall, ScriptDependency, RuntimeChoices
2021
from syncano.connection import Connection
2122

22-
# 1. Initialize the custom socket.
23+
# 1. Initialize a custom socket.
2324
custom_socket = CustomSocket(name='my_custom_socket') # this will create an object in place (do API call)
2425

2526
# 2. Define endpoints.
26-
my_endpoint = Endpoint(name='my_endpoint') # again - no API call here
27+
my_endpoint = Endpoint(name='my_endpoint') # no API call here
2728
my_endpoint.add_call(ScriptCall(name='custom_script'), methods=['GET'])
2829
my_endpoint.add_call(ScriptCall(name='another_custom_script'), methods=['POST'])
2930

30-
# explanation for the above lines:
31-
# The endpoint will be seen under `my_endpoint` name:
31+
# Explanation of the above lines:
32+
# Defined endpoint will be visible under `my_endpoint` name:
3233
# On this syncano API endpoint the above endpoint will be called (after custom socket creation)
3334
# <host>://<api_version>/instances/<instance_name>/endpoints/sockets/my_endpoint/
3435
# On this syncano API endpoint the details of the defined endpoint will be returned
@@ -37,11 +38,11 @@ To create a custom socket follow these steps::
3738
# there, second uses the POST method and then the another_custom_script will be called;
3839
# Currently only script are available for calls;
3940

40-
# 3. After the creation of the endpoint, add them to custom_socket.
41+
# 3. After creation of the endpoint, add it to your custom_socket.
4142
custom_socket.add_endpoint(my_endpoint)
4243

43-
# 4. Define dependency now.
44-
# 4.1 using a new script - defining new source code.
44+
# 4. Define dependency.
45+
# 4.1 Using a new script - define a new source code.
4546
custom_socket.add_dependency(
4647
ScriptDependency(
4748
name='custom_script'
@@ -51,7 +52,7 @@ To create a custom socket follow these steps::
5152
)
5253
)
5354
)
54-
# 4.2 using an existing script.
55+
# 4.2 Using an existing script.
5556
another_custom_script = Script.please.get(id=2)
5657
custom_socket.add_dependency(
5758
ScriptDependency(
@@ -60,19 +61,19 @@ To create a custom socket follow these steps::
6061
)
6162
)
6263

63-
# 4.3 using an existing ScriptEndpoint.
64+
# 4.3 Using an existing ScriptEndpoint.
6465
script_endpoint = ScriptEndpoint.please.get(name='script_endpoint_name')
6566
custom_socket.add_dependency(
6667
script_endpoint=script_endpoint
6768
)
6869

6970
# 5. Publish custom_socket.
70-
custom_socket.publish() # this will do an API call and will create script;
71+
custom_socket.publish() # this will make an API call and create a script;
7172

72-
Some time is needed to setup the environment for this custom socket.
73-
There is possibility to check the custom socket status::
73+
Sometimes, it's needed to set up the environment for the custom socket.
74+
It's possible to check the custom socket status::
7475

75-
# Reload will refresh object using syncano API.
76+
# Reload will refresh object using Syncano API.
7677
custom_socket.reload()
7778
print(custom_socket.status)
7879
# and
@@ -85,30 +86,34 @@ To update custom socket, use::
8586

8687
custom_socket = CustomSocket.please.get(name='my_custom_socket')
8788

89+
# to remove endpoint/dependency
90+
8891
custom_socket.remove_endpoint(endpoint_name='my_endpoint')
8992
custom_socket.remove_dependency(dependency_name='custom_script')
9093

91-
# or add new:
94+
# or to add a new endpoint/dependency:
9295

9396
custom_socket.add_endpoint(new_endpoint) # see above code for endpoint examples;
9497
custom_socket.add_dependency(new_dependency) # see above code for dependency examples;
9598

99+
# save changes on Syncano
100+
96101
custom_socket.update()
97102

98103

99-
Running the custom socket
104+
Running custom socket
100105
-------------------------
101106

102-
To run custom socket use::
107+
To run a custom socket use::
103108

104-
# this will run the my_endpoint - and call the custom_script (method is GET);
109+
# this will run `my_endpoint` - and call `custom_script` (using GET method);
105110
result = custom_socket.run(method='GET', endpoint_name='my_endpoint')
106111

107112

108-
Read all endpoints in custom socket
113+
Read all endpoints in a custom socket
109114
-----------------------------------
110115

111-
To get the all defined endpoints in custom socket run::
116+
To get the all defined endpoints in a custom socket run::
112117

113118
endpoints = custom_socket.get_endpoints()
114119

@@ -122,7 +127,7 @@ To run a particular endpoint::
122127
# or:
123128
endpoint.run(method='POST', data={'name': 'test_name'})
124129

125-
The data will be passed to the API call in the request body.
130+
Data will be passed to the API call in the request body.
126131

127132
Read all endpoints
128133
------------------
@@ -140,16 +145,16 @@ Above code will return a list with SocketEndpoint objects. To run such endpoint,
140145
Custom sockets endpoints
141146
------------------------
142147

143-
Each custom socket requires to define at least one endpoint. The endpoint is defined by name and
144-
a list of calls. Each call is defined by a name and a list of methods. The name is a identification for dependency, eg.
148+
Each custom socket requires a definition of at least one endpoint. This endpoint is defined by name and
149+
a list of calls. Each call is defined by its name and a list of methods. Name is used in identification for dependency, eg.
145150
if it's equal to 'my_script' - the ScriptEndpoint with name 'my_script' will be used
146-
(if it exists and Script source and runtime matches) or a new one will be created.
147-
There's a special wildcard method: `methods=['*']` - this mean that any request with
151+
(if it exists and Script source and passed runtime match) -- otherwise a new one will be created.
152+
There's a special wildcard method: `methods=['*']` - it means that any request with
148153
any method will be executed in this endpoint.
149154

150-
To add an endpoint to the custom_socket use::
155+
To add an endpoint to a chosen custom_socket use::
151156

152-
my_endpoint = Endpoint(name='my_endpoint') # again - no API call here
157+
my_endpoint = Endpoint(name='my_endpoint') # no API call here
153158
my_endpoint.add_call(ScriptCall(name='custom_script'), methods=['GET'])
154159
my_endpoint.add_call(ScriptCall(name='another_custom_script'), methods=['POST'])
155160

@@ -158,9 +163,9 @@ To add an endpoint to the custom_socket use::
158163
Custom socket dependency
159164
------------------------
160165

161-
Each custom socket has dependency - this is a meta information for endpoint: which resource
162-
should be used to return the API call results. The dependencies are bind to the endpoints call objects.
163-
Currently the only supported dependency is script.
166+
Each custom socket has a dependency -- meta information for an endpoint: which resource
167+
should be used to return the API call results. These dependencies are bound to the endpoints call objects.
168+
Currently the only supported dependency is a Script.
164169

165170
**Using new script**
166171

@@ -201,15 +206,15 @@ Currently the only supported dependency is script.
201206
Custom socket recheck
202207
---------------------
203208

204-
The creation of the socket can fail - this happen, eg. when endpoint name is already taken by another
209+
The creation of the socket can fail - this can happen, e.g. when an endpoint name is already taken by another
205210
custom socket. To check the statuses use::
206211

207212
print(custom_socket.status)
208213
print(custom_socket.status_info)
209214

210215
There is a possibility to re-check socket - this mean that if conditions are met - the socket endpoints and dependencies
211-
will be checked - and if some of them are missing (eg. mistake deletion), they will be created again.
212-
If the endpoints and dependencies do not met the criteria - the error will be returned in the status field.
216+
will be checked - and if some of them are missing (e.g. some were deleted by mistake), they will be created again.
217+
If the endpoints and dependencies do not meet the criteria - an error will be returned in the status field.
213218

214219
Custom socket - raw format
215220
--------------------------
@@ -236,4 +241,4 @@ If you prefer raw JSON format for creating sockets, you can resort to use it in
236241
]
237242
)
238243

239-
The disadvantage of this method is that - the JSON internal structure must be known by developer.
244+
The disadvantage of this method is that internal structure of the JSON file must be known by developer.

0 commit comments

Comments
 (0)