1
0
Fork 0
mirror of synced 2024-06-29 11:40:45 +12:00

Pass custom function $data to execution

This commit is contained in:
kodumbeats 2021-03-09 14:58:03 -05:00
parent 70935fe75b
commit 59984fa6c0
2 changed files with 10 additions and 5 deletions

View file

@ -672,11 +672,12 @@ App::post('/v1/functions/:functionId/executions')
->label('abuse-limit', 60) ->label('abuse-limit', 60)
->label('abuse-time', 60) ->label('abuse-time', 60)
->param('functionId', '', new UID(), 'Function unique ID.') ->param('functionId', '', new UID(), 'Function unique ID.')
->param('data', '', new Text(8192), 'String of custom data to send to function.', true)
// ->param('async', 1, new Range(0, 1), 'Execute code asynchronously. Pass 1 for true, 0 for false. Default value is 1.', true) // ->param('async', 1, new Range(0, 1), 'Execute code asynchronously. Pass 1 for true, 0 for false. Default value is 1.', true)
->inject('response') ->inject('response')
->inject('project') ->inject('project')
->inject('projectDB') ->inject('projectDB')
->action(function ($functionId, /*$async,*/ $response, $project, $projectDB) { ->action(function ($functionId, $data, /*$async,*/ $response, $project, $projectDB) {
/** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Document $project */
/** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Database\Database $projectDB */
@ -736,6 +737,7 @@ App::post('/v1/functions/:functionId/executions')
'functionId' => $function->getId(), 'functionId' => $function->getId(),
'executionId' => $execution->getId(), 'executionId' => $execution->getId(),
'trigger' => 'http', 'trigger' => 'http',
'data' => $data,
]); ]);
$response $response

View file

@ -148,6 +148,7 @@ class FunctionsV1
$event = $this->args['event'] ?? ''; $event = $this->args['event'] ?? '';
$scheduleOriginal = $this->args['scheduleOriginal'] ?? ''; $scheduleOriginal = $this->args['scheduleOriginal'] ?? '';
$payload = (!empty($this->args['payload'])) ? json_encode($this->args['payload']) : ''; $payload = (!empty($this->args['payload'])) ? json_encode($this->args['payload']) : '';
$data = $this->args['data'] ?? '';
$database = new Database(); $database = new Database();
$database->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register)); $database->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register));
@ -195,7 +196,7 @@ class FunctionsV1
Console::success('Triggered function: '.$event); Console::success('Triggered function: '.$event);
$this->execute('event', $projectId, '', $database, $function, $event, $payload); $this->execute('event', $projectId, '', $database, $function, $event, $payload, $data);
} }
} }
break; break;
@ -251,7 +252,7 @@ class FunctionsV1
'scheduleOriginal' => $function->getAttribute('schedule', ''), 'scheduleOriginal' => $function->getAttribute('schedule', ''),
]); // Async task rescheduale ]); // Async task rescheduale
$this->execute($trigger, $projectId, $executionId, $database, $function); $this->execute($trigger, $projectId, $executionId, $database, $function, /*$event*/'', /*$payload*/'', $data);
break; break;
@ -264,7 +265,7 @@ class FunctionsV1
throw new Exception('Function not found ('.$functionId.')'); throw new Exception('Function not found ('.$functionId.')');
} }
$this->execute($trigger, $projectId, $executionId, $database, $function); $this->execute($trigger, $projectId, $executionId, $database, $function, /*$event*/'', /*$payload*/'', $data);
break; break;
default: default:
@ -283,10 +284,11 @@ class FunctionsV1
* @param Database $function * @param Database $function
* @param string $event * @param string $event
* @param string $payload * @param string $payload
* @param string $data
* *
* @return void * @return void
*/ */
public function execute(string $trigger, string $projectId, string $executionId, Database $database, Document $function, string $event = '', string $payload = ''): void public function execute(string $trigger, string $projectId, string $executionId, Database $database, Document $function, string $event = '', string $payload = '', string $data = ''): void
{ {
global $list; global $list;
@ -341,6 +343,7 @@ class FunctionsV1
'APPWRITE_FUNCTION_ENV_VERSION' => $environment['version'], 'APPWRITE_FUNCTION_ENV_VERSION' => $environment['version'],
'APPWRITE_FUNCTION_EVENT' => $event, 'APPWRITE_FUNCTION_EVENT' => $event,
'APPWRITE_FUNCTION_EVENT_PAYLOAD' => $payload, 'APPWRITE_FUNCTION_EVENT_PAYLOAD' => $payload,
'APPWRITE_FUNCTION_DATA' => $data,
]); ]);
\array_walk($vars, function (&$value, $key) { \array_walk($vars, function (&$value, $key) {