Class: Appwrite::Functions

Inherits:
Service
  • Object
show all
Defined in:
lib/appwrite/services/functions.rb

Instance Method Summary collapse

Methods inherited from Service

#initialize

Constructor Details

This class inherits a constructor from Appwrite::Service

Instance Method Details

#create(function_id:, name:, execute:, runtime:, vars: nil, events: nil, schedule: nil, timeout: nil) ⇒ Function

Create a new function. You can pass a list of [permissions](/docs/permissions) to allow different project users or team with access to execute the function using the client API.

Parameters:

  • function_id (string)

    Function ID. Choose your own unique ID or pass the string "unique()" to auto generate it. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.

  • name (string)

    Function name. Max length: 128 chars.

  • execute (array)

    An array of strings with execution permissions. By default no user is granted with any execute permissions. [learn more about permissions](appwrite.io/docs/permissions) and get a full list of available permissions.

  • runtime (string)

    Execution runtime.

  • vars (object) (defaults to: nil)

    Key-value JSON object that will be passed to the function as environment variables.

  • events (array) (defaults to: nil)

    Events list.

  • schedule (string) (defaults to: nil)

    Schedule CRON syntax.

  • timeout (number) (defaults to: nil)

    Function maximum execution time in seconds.

Returns:

  • (Function)


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/appwrite/services/functions.rb', line 56

def create(function_id:, name:, execute:, runtime:, vars: nil, events: nil, schedule: nil, timeout: nil)
    if function_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    if name.nil?
        raise Appwrite::Exception.new('Missing required parameter: "name"')
    end

    if execute.nil?
        raise Appwrite::Exception.new('Missing required parameter: "execute"')
    end

    if runtime.nil?
        raise Appwrite::Exception.new('Missing required parameter: "runtime"')
    end

    path = '/functions'

    params = {
        functionId: function_id,
        name: name,
        execute: execute,
        runtime: runtime,
        vars: vars,
        events: events,
        schedule: schedule,
        timeout: timeout,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::Function
    )
end

#create_deployment(function_id:, entrypoint:, code:, activate:, on_progress: nil) ⇒ Deployment

Create a new function code deployment. Use this endpoint to upload a new version of your code function. To execute your newly uploaded code, you’ll need to update the function’s deployment to use your new deployment UID.

This endpoint accepts a tar.gz file compressed with your code. Make sure to include any dependencies your code has within the compressed file. You can learn more about code packaging in the [Appwrite Cloud Functions tutorial](/docs/functions).

Use the “command” param to set the entry point used to execute your code.

Parameters:

  • function_id (string)

    Function ID.

  • entrypoint (string)

    Entrypoint File.

  • code (file)

    Gzip file with your code package. When used with the Appwrite CLI, pass the path to your code directory, and the CLI will automatically package your code. Use a path that is within the current directory.

  • activate (boolean)

    Automatically activate the deployment when it is finished building.

Returns:

  • (Deployment)


287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'lib/appwrite/services/functions.rb', line 287

def create_deployment(function_id:, entrypoint:, code:, activate:, on_progress: nil)
    if function_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    if entrypoint.nil?
        raise Appwrite::Exception.new('Missing required parameter: "entrypoint"')
    end

    if code.nil?
        raise Appwrite::Exception.new('Missing required parameter: "code"')
    end

    if activate.nil?
        raise Appwrite::Exception.new('Missing required parameter: "activate"')
    end

    path = '/functions/{functionId}/deployments'
        .gsub('{functionId}', function_id)

    params = {
        entrypoint: entrypoint,
        code: code,
        activate: activate,
    }

    headers = {
        "content-type": 'multipart/form-data',
    }

    id_param_name = nil
    param_name = 'code'

    @client.chunked_upload(
        path: path,
        headers: headers,
        params: params,
        param_name: param_name,
        id_param_name: id_param_name,
        on_progress: on_progress,
        response_type: Models::Deployment
    )
end

#create_execution(function_id:, data: nil, async: nil) ⇒ Execution

Trigger a function execution. The returned object will return you the current execution status. You can ping the ‘Get Execution` endpoint to get updates on the current execution status. Once this endpoint is called, your function execution process will start asynchronously.

Parameters:

  • function_id (string)

    Function ID.

  • data (string) (defaults to: nil)

    String of custom data to send to function.

  • async (boolean) (defaults to: nil)

    Execute code asynchronously. Default value is true.

Returns:

  • (Execution)


529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
# File 'lib/appwrite/services/functions.rb', line 529

def create_execution(function_id:, data: nil, async: nil)
    if function_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    path = '/functions/{functionId}/executions'
        .gsub('{functionId}', function_id)

    params = {
        data: data,
        async: async,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::Execution
    )
end

#delete(function_id:) ⇒ Object

Delete a function by its unique ID.

Parameters:

  • function_id (string)

    Function ID.

Returns:



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/appwrite/services/functions.rb', line 205

def delete(function_id:)
    if function_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    path = '/functions/{functionId}'
        .gsub('{functionId}', function_id)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'DELETE',
        path: path,
        headers: headers,
        params: params,
    )
end

#delete_deployment(function_id:, deployment_id:) ⇒ Object

Delete a code deployment by its unique ID.

Parameters:

  • function_id (string)

    Function ID.

  • deployment_id (string)

    Deployment ID.

Returns:



409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
# File 'lib/appwrite/services/functions.rb', line 409

def delete_deployment(function_id:, deployment_id:)
    if function_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    if deployment_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "deploymentId"')
    end

    path = '/functions/{functionId}/deployments/{deploymentId}'
        .gsub('{functionId}', function_id)
        .gsub('{deploymentId}', deployment_id)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'DELETE',
        path: path,
        headers: headers,
        params: params,
    )
end

#get(function_id:) ⇒ Function

Get a function by its unique ID.

Parameters:

  • function_id (string)

    Function ID.

Returns:

  • (Function)


127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/appwrite/services/functions.rb', line 127

def get(function_id:)
    if function_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    path = '/functions/{functionId}'
        .gsub('{functionId}', function_id)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::Function
    )
end

#get_deployment(function_id:, deployment_id:) ⇒ DeploymentList

Get a code deployment by its unique ID.

Parameters:

  • function_id (string)

    Function ID.

  • deployment_id (string)

    Deployment ID.

Returns:

  • (DeploymentList)


337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# File 'lib/appwrite/services/functions.rb', line 337

def get_deployment(function_id:, deployment_id:)
    if function_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    if deployment_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "deploymentId"')
    end

    path = '/functions/{functionId}/deployments/{deploymentId}'
        .gsub('{functionId}', function_id)
        .gsub('{deploymentId}', deployment_id)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::DeploymentList
    )
end

#get_execution(function_id:, execution_id:) ⇒ Execution

Get a function execution log by its unique ID.

Parameters:

  • function_id (string)

    Function ID.

  • execution_id (string)

    Execution ID.

Returns:

  • (Execution)


561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
# File 'lib/appwrite/services/functions.rb', line 561

def get_execution(function_id:, execution_id:)
    if function_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    if execution_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "executionId"')
    end

    path = '/functions/{functionId}/executions/{executionId}'
        .gsub('{functionId}', function_id)
        .gsub('{executionId}', execution_id)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::Execution
    )
end

#list(search: nil, limit: nil, offset: nil, cursor: nil, cursor_direction: nil, order_type: nil) ⇒ FunctionList

Get a list of all the project’s functions. You can use the query params to filter your results.

Parameters:

  • search (string) (defaults to: nil)

    Search term to filter your list results. Max length: 256 chars.

  • limit (number) (defaults to: nil)

    Maximum number of functions to return in response. By default will return maximum 25 results. Maximum of 100 results allowed per request.

  • offset (number) (defaults to: nil)

    Offset value. The default value is 0. Use this value to manage pagination. [learn more about pagination](appwrite.io/docs/pagination)

  • cursor (string) (defaults to: nil)

    ID of the function used as the starting point for the query, excluding the function itself. Should be used for efficient pagination when working with large sets of data. [learn more about pagination](appwrite.io/docs/pagination)

  • cursor_direction (string) (defaults to: nil)

    Direction of the cursor.

  • order_type (string) (defaults to: nil)

    Order result by ASC or DESC order.

Returns:

  • (FunctionList)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/appwrite/services/functions.rb', line 17

def list(search: nil, limit: nil, offset: nil, cursor: nil, cursor_direction: nil, order_type: nil)
    path = '/functions'

    params = {
        search: search,
        limit: limit,
        offset: offset,
        cursor: cursor,
        cursorDirection: cursor_direction,
        orderType: order_type,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::FunctionList
    )
end

#list_deployments(function_id:, search: nil, limit: nil, offset: nil, cursor: nil, cursor_direction: nil, order_type: nil) ⇒ DeploymentList

Get a list of all the project’s code deployments. You can use the query params to filter your results.

Parameters:

  • function_id (string)

    Function ID.

  • search (string) (defaults to: nil)

    Search term to filter your list results. Max length: 256 chars.

  • limit (number) (defaults to: nil)

    Maximum number of deployments to return in response. By default will return maximum 25 results. Maximum of 100 results allowed per request.

  • offset (number) (defaults to: nil)

    Offset value. The default value is 0. Use this value to manage pagination. [learn more about pagination](appwrite.io/docs/pagination)

  • cursor (string) (defaults to: nil)

    ID of the deployment used as the starting point for the query, excluding the deployment itself. Should be used for efficient pagination when working with large sets of data. [learn more about pagination](appwrite.io/docs/pagination)

  • cursor_direction (string) (defaults to: nil)

    Direction of the cursor.

  • order_type (string) (defaults to: nil)

    Order result by ASC or DESC order.

Returns:

  • (DeploymentList)


240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/appwrite/services/functions.rb', line 240

def list_deployments(function_id:, search: nil, limit: nil, offset: nil, cursor: nil, cursor_direction: nil, order_type: nil)
    if function_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    path = '/functions/{functionId}/deployments'
        .gsub('{functionId}', function_id)

    params = {
        search: search,
        limit: limit,
        offset: offset,
        cursor: cursor,
        cursorDirection: cursor_direction,
        orderType: order_type,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::DeploymentList
    )
end

#list_executions(function_id:, limit: nil, offset: nil, search: nil, cursor: nil, cursor_direction: nil) ⇒ ExecutionList

Get a list of all the current user function execution logs. You can use the query params to filter your results. On admin mode, this endpoint will return a list of all of the project’s executions. [Learn more about different API modes](/docs/admin).

Parameters:

  • function_id (string)

    Function ID.

  • limit (number) (defaults to: nil)

    Maximum number of executions to return in response. By default will return maximum 25 results. Maximum of 100 results allowed per request.

  • offset (number) (defaults to: nil)

    Offset value. The default value is 0. Use this value to manage pagination. [learn more about pagination](appwrite.io/docs/pagination)

  • search (string) (defaults to: nil)

    Search term to filter your list results. Max length: 256 chars.

  • cursor (string) (defaults to: nil)

    ID of the execution used as the starting point for the query, excluding the execution itself. Should be used for efficient pagination when working with large sets of data. [learn more about pagination](appwrite.io/docs/pagination)

  • cursor_direction (string) (defaults to: nil)

    Direction of the cursor.

Returns:

  • (ExecutionList)


490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
# File 'lib/appwrite/services/functions.rb', line 490

def list_executions(function_id:, limit: nil, offset: nil, search: nil, cursor: nil, cursor_direction: nil)
    if function_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    path = '/functions/{functionId}/executions'
        .gsub('{functionId}', function_id)

    params = {
        limit: limit,
        offset: offset,
        search: search,
        cursor: cursor,
        cursorDirection: cursor_direction,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::ExecutionList
    )
end

#list_runtimesRuntimeList

Get a list of all runtimes that are currently active on your instance.

Returns:

  • (RuntimeList)


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/appwrite/services/functions.rb', line 103

def list_runtimes()
    path = '/functions/runtimes'

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::RuntimeList
    )
end

#retry_build(function_id:, deployment_id:, build_id:) ⇒ Object

Returns [].

Parameters:

  • function_id (string)

    Function ID.

  • deployment_id (string)

    Deployment ID.

  • build_id (string)

    Build unique ID.

Returns:



444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
# File 'lib/appwrite/services/functions.rb', line 444

def retry_build(function_id:, deployment_id:, build_id:)
    if function_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    if deployment_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "deploymentId"')
    end

    if build_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "buildId"')
    end

    path = '/functions/{functionId}/deployments/{deploymentId}/builds/{buildId}'
        .gsub('{functionId}', function_id)
        .gsub('{deploymentId}', deployment_id)
        .gsub('{buildId}', build_id)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: path,
        headers: headers,
        params: params,
    )
end

#update(function_id:, name:, execute:, vars: nil, events: nil, schedule: nil, timeout: nil) ⇒ Function

Update function by its unique ID.

Parameters:

  • function_id (string)

    Function ID.

  • name (string)

    Function name. Max length: 128 chars.

  • execute (array)

    An array of strings with execution permissions. By default no user is granted with any execute permissions. [learn more about permissions](appwrite.io/docs/permissions) and get a full list of available permissions.

  • vars (object) (defaults to: nil)

    Key-value JSON object that will be passed to the function as environment variables.

  • events (array) (defaults to: nil)

    Events list.

  • schedule (string) (defaults to: nil)

    Schedule CRON syntax.

  • timeout (number) (defaults to: nil)

    Maximum execution time in seconds.

Returns:

  • (Function)


162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/appwrite/services/functions.rb', line 162

def update(function_id:, name:, execute:, vars: nil, events: nil, schedule: nil, timeout: nil)
    if function_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    if name.nil?
        raise Appwrite::Exception.new('Missing required parameter: "name"')
    end

    if execute.nil?
        raise Appwrite::Exception.new('Missing required parameter: "execute"')
    end

    path = '/functions/{functionId}'
        .gsub('{functionId}', function_id)

    params = {
        name: name,
        execute: execute,
        vars: vars,
        events: events,
        schedule: schedule,
        timeout: timeout,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'PUT',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::Function
    )
end

#update_deployment(function_id:, deployment_id:) ⇒ Function

Update the function code deployment ID using the unique function ID. Use this endpoint to switch the code deployment that should be executed by the execution endpoint.

Parameters:

  • function_id (string)

    Function ID.

  • deployment_id (string)

    Deployment ID.

Returns:

  • (Function)


374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# File 'lib/appwrite/services/functions.rb', line 374

def update_deployment(function_id:, deployment_id:)
    if function_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    if deployment_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "deploymentId"')
    end

    path = '/functions/{functionId}/deployments/{deploymentId}'
        .gsub('{functionId}', function_id)
        .gsub('{deploymentId}', deployment_id)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'PATCH',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::Function
    )
end