From 2e5815e474982fff415bc261f755b794dbf8c74b Mon Sep 17 00:00:00 2001 From: Yannis Weishaupt Date: Fri, 10 Jan 2020 18:08:14 +0100 Subject: [PATCH 01/10] Use the GraphQL API v2 for the serverless code path --- CHANGELOG.md | 3 +- src/Code/serverless/Client/Alfred.js | 291 ++++++++------------------- 2 files changed, 82 insertions(+), 212 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed3791d..61bbcd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,13 +9,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) ### Changed - Change the ZENATON `LAST_CODE_PATH` to `serverless`. -- Allow the selection of workflows without a name. +- Use the GraphQL API v2 for the `serverless` code path. ## 0.7.4 - 2020-01-20 ### Fixed - Fixed selector query input. +- Allow selection of workflows without name. ## 0.7.3 - 2020-01-13 diff --git a/src/Code/serverless/Client/Alfred.js b/src/Code/serverless/Client/Alfred.js index 4337f8d..4023d6d 100644 --- a/src/Code/serverless/Client/Alfred.js +++ b/src/Code/serverless/Client/Alfred.js @@ -1,6 +1,4 @@ -const uuidv4 = require("uuid/v4"); const { GraphQLClient } = require("graphql-request"); -const { version: libVersion } = require("../../../infos"); const { serializer, versioner } = require("../Services"); const Job = require("./Job"); const { @@ -14,22 +12,10 @@ const ZENATON_GATEWAY_BASE_URL = "https://gateway.zenaton.com"; const APP_ENV = "app_env"; const APP_ID = "app_id"; -const ATTR_INTENT_ID = "intent_id"; -const ATTR_CUSTOM_ID = "custom_id"; +const ATTR_TAG = "tag"; const ATTR_NAME = "name"; -const ATTR_CANONICAL = "canonical_name"; const ATTR_VERSION = "version"; const ATTR_INPUT = "input"; -const ATTR_PROPERTIES = "properties"; - -const ATTR_PROG = "programming_language"; -const ATTR_INITIAL_LIB_VERSION = "initial_library_version"; -const ATTR_CODE_PATH_VERSION = "code_path_version"; -const ATTR_MAX_PROCESSING_TIME = "maxProcessingTime"; - -const PROG = "Javascript"; -const INITIAL_LIB_VERSION = libVersion; -const CODE_PATH_VERSION = process.env.ZENATON_LAST_CODE_PATH; const Alfred = class Alfred { constructor(client) { @@ -46,19 +32,13 @@ const Alfred = class Alfred { const variables = { dispatchTaskInput: { - intentId: body[ATTR_INTENT_ID], - environmentName: this.client.appEnv, + appId: this.client.appId, + environment: this.client.appEnv, name: body[ATTR_NAME], - programmingLanguage: body[ATTR_PROG].toUpperCase(), - maxProcessingTime: body[ATTR_MAX_PROCESSING_TIME], - data: body[ATTR_INPUT], - codePathVersion: body[ATTR_CODE_PATH_VERSION], - initialLibraryVersion: body[ATTR_INITIAL_LIB_VERSION], + input: body[ATTR_INPUT], }, }; - const job = new Job({ - id: body[ATTR_INTENT_ID], - }); + const job = new Job(); const promise = this._request(endpoint, mutation, variables).then( (res) => res.dispatchTask, ); @@ -73,22 +53,17 @@ const Alfred = class Alfred { scheduleTask(task) { const endpoint = this._getGatewayUrl(); const body = this._getBodyForTask(task); - const mutation = mutations.createTaskSchedule; + const mutation = mutations.scheduleTask; const variables = { - createTaskScheduleInput: { - intentId: body[ATTR_INTENT_ID], - environmentName: this.client.appEnv, + scheduleTaskInput: { + appId: this.client.appId, + environment: this.client.appEnv, cron: task.scheduling.cron, - taskName: body[ATTR_NAME], - programmingLanguage: body[ATTR_PROG].toUpperCase(), - properties: body[ATTR_INPUT], - codePathVersion: body[ATTR_CODE_PATH_VERSION], - initialLibraryVersion: body[ATTR_INITIAL_LIB_VERSION], + name: body[ATTR_NAME], + input: body[ATTR_INPUT], }, }; - const job = new Job({ - id: body[ATTR_INTENT_ID], - }); + const job = new Job(); const promise = this._request(endpoint, mutation, variables).then( (res) => res.createTaskSchedule, ); @@ -106,21 +81,15 @@ const Alfred = class Alfred { const mutation = mutations.dispatchWorkflow; const variables = { dispatchWorkflowInput: { - intentId: body[ATTR_INTENT_ID], - environmentName: this.client.appEnv, + appId: this.client.appId, + environment: this.client.appEnv, name: body[ATTR_NAME], - customId: body[ATTR_CUSTOM_ID], - canonicalName: body[ATTR_CANONICAL], - programmingLanguage: body[ATTR_PROG].toUpperCase(), input: body[ATTR_INPUT], - data: body[ATTR_PROPERTIES], - codePathVersion: body[ATTR_CODE_PATH_VERSION], - initialLibraryVersion: body[ATTR_INITIAL_LIB_VERSION], + tag: body[ATTR_TAG], + version: body[ATTR_VERSION], }, }; - const job = new Job({ - id: body[ATTR_INTENT_ID], - }); + const job = new Job(); const promise = this._request(endpoint, mutation, variables).then( (res) => res.dispatchWorkflow, ); @@ -135,27 +104,21 @@ const Alfred = class Alfred { scheduleWorkflow(w) { const endpoint = this._getGatewayUrl(); const body = this._getBodyForWorkflow(w); - const mutation = mutations.createWorkflowSchedule; + const mutation = mutations.scheduleWorkflow; const variables = { - createWorkflowScheduleInput: { - intentId: body[ATTR_INTENT_ID], - environmentName: this.client.appEnv, + scheduleWorkflow: { + appId: this.client.appId, + environment: this.client.appEnv, cron: w.scheduling.cron, - workflowName: body[ATTR_NAME], - customId: body[ATTR_CUSTOM_ID], - canonicalName: body[ATTR_CANONICAL], - programmingLanguage: body[ATTR_PROG].toUpperCase(), + name: body[ATTR_NAME], + tag: body[ATTR_TAG], input: body[ATTR_INPUT], - properties: body[ATTR_PROPERTIES], - codePathVersion: body[ATTR_CODE_PATH_VERSION], - initialLibraryVersion: body[ATTR_INITIAL_LIB_VERSION], + version: body[ATTR_VERSION], }, }; - const job = new Job({ - id: body[ATTR_INTENT_ID], - }); + const job = new Job(); const promise = this._request(endpoint, mutation, variables).then( - (res) => res.createWorkflowSchedule, + (res) => res.scheduleWorkflow, ); job.promise = promise; @@ -166,21 +129,18 @@ const Alfred = class Alfred { * Terminate a workflow instance */ terminateWorkflow(query) { - const intentId = uuidv4(); const endpoint = this._getGatewayUrl(); const mutation = mutations.terminateWorkflows; const variables = { - killWorkflowsInput: { - intentId, - environmentName: this.client.appEnv, + terminateWorkflowsInput: { + appId: this.client.appId, + environment: this.client.appEnv, selector: query, }, }; - const job = new Job({ - id: intentId, - }); + const job = new Job(); const promise = this._request(endpoint, mutation, variables).then( (res) => res.killWorkflows, ); @@ -193,19 +153,16 @@ const Alfred = class Alfred { * Pause a workflow instance */ pauseWorkflow(query) { - const intentId = uuidv4(); const endpoint = this._getGatewayUrl(); const mutation = mutations.pauseWorkflows; const variables = { pauseWorkflowsInput: { - intentId, - environmentName: this.client.appEnv, + appId: this.client.appId, + environment: this.client.appEnv, selector: query, }, }; - const job = new Job({ - id: intentId, - }); + const job = new Job(); const promise = this._request(endpoint, mutation, variables).then( (res) => res.pauseWorkflows, ); @@ -218,19 +175,16 @@ const Alfred = class Alfred { * Resume a workflow instance */ resumeWorkflow(query) { - const intentId = uuidv4(); const endpoint = this._getGatewayUrl(); const mutation = mutations.resumeWorkflows; const variables = { resumeWorkflowsInput: { - intentId, - environmentName: this.client.appEnv, + appId: this.client.appId, + environment: this.client.appEnv, selector: query, }, }; - const job = new Job({ - id: intentId, - }); + const job = new Job(); const promise = this._request(endpoint, mutation, variables).then( (res) => res.resumeWorkflows, ); @@ -243,26 +197,19 @@ const Alfred = class Alfred { * Send an event to a workflow instance */ sendEvent(query, eventName, eventData) { - const intentId = uuidv4(); const endpoint = this._getGatewayUrl(); const mutation = mutations.sendEventToWorkflows; const variables = { sendEventToWorkflowsInput: { - intent_id: intentId, - environmentName: this.client.appEnv, - data: serializer.encode({ - name: eventName, - data: eventData, - }), + appId: this.client.appId, + environment: this.client.appEnv, name: eventName, input: serializer.encode(eventData), selector: query, }, }; - const job = new Job({ - id: intentId, - }); + const job = new Job(); const promise = this._request(endpoint, mutation, variables).then( (res) => res.sendEventToWorkflows, ); @@ -277,23 +224,19 @@ const Alfred = class Alfred { sendEventByInstanceId(id, eventName, eventData) { const endpoint = this._getGatewayUrl(); - const mutation = mutations.sendEventToWorkflowById; + const mutation = mutations.sendEventToWorkflows; const variables = { - sendEventToWorkflowByIdInput: { - id, - eventName, - eventInput: serializer.encode(eventData), - eventData: serializer.encode({ - name: eventName, - data: eventData, - }), + sendEventToWorkflowsInput: { + appId: this.client.appId, + environment: this.client.appEnv, + name: eventName, + input: serializer.encode(eventData), + selector: { id }, }, }; - const job = new Job({ - id: uuidv4(), - }); + const job = new Job(); const promise = this._request(endpoint, mutation, variables).then( - (res) => res.sendEventToWorkflowById, + (res) => res.sendEventToWorkflows, ); job.promise = promise; @@ -305,7 +248,7 @@ const Alfred = class Alfred { ? process.env.ZENATON_GATEWAY_URL : ZENATON_GATEWAY_BASE_URL; - return `${host}/api`; + return `${host}/graphql`; } async _request(endpoint, query, variables) { @@ -314,8 +257,7 @@ const Alfred = class Alfred { headers: { Accept: "application/json", "Content-Type": "application/json", - "app-id": this.client.appId, - "api-token": this.client.apiToken, + Authorization: `Bearer ${this.client.apiToken}`, }, }); @@ -341,12 +283,7 @@ const Alfred = class Alfred { const { canonical, version } = versioner(job.name); return { - [ATTR_INTENT_ID]: uuidv4(), - [ATTR_PROG]: PROG, - [ATTR_INITIAL_LIB_VERSION]: INITIAL_LIB_VERSION, - [ATTR_CODE_PATH_VERSION]: CODE_PATH_VERSION, - [ATTR_NAME]: job.name, - [ATTR_CANONICAL]: canonical, + [ATTR_NAME]: canonical, [ATTR_VERSION]: version, [ATTR_INPUT]: serializer.encode(job.input), }; @@ -356,16 +293,10 @@ const Alfred = class Alfred { const { canonical, version } = versioner(job.name); return { - [ATTR_INTENT_ID]: uuidv4(), - [ATTR_PROG]: PROG, - [ATTR_INITIAL_LIB_VERSION]: INITIAL_LIB_VERSION, - [ATTR_CODE_PATH_VERSION]: CODE_PATH_VERSION, - [ATTR_NAME]: job.name, - [ATTR_CANONICAL]: canonical, + [ATTR_NAME]: canonical, [ATTR_VERSION]: version, [ATTR_INPUT]: serializer.encode(job.input), - [ATTR_PROPERTIES]: serializer.encode({}), - [ATTR_CUSTOM_ID]: job.customId ? job.customId : null, + [ATTR_TAG]: job.customId ? job.customId : null, }; } @@ -417,115 +348,53 @@ const Alfred = class Alfred { const mutations = { dispatchTask: ` - mutation ($dispatchTaskInput: DispatchTaskInput!) { - dispatchTask(input: $dispatchTaskInput) { - task { - intentId - } + mutation($input: DispatchTaskInput!) { + dispatchTask(input: $input) { + id } }`, dispatchWorkflow: ` - mutation ($dispatchWorkflowInput: DispatchWorkflowInput!) { - dispatchWorkflow(input: $dispatchWorkflowInput) { - workflow { - id - canonicalName - name - programmingLanguage - properties - } + mutation($input: DispatchWorkflowInput!) { + dispatchWorkflow(input: $input) { + id } }`, terminateWorkflows: ` - mutation ($killWorkflowsInput: KillWorkflowsInput!) { - killWorkflows(input: $killWorkflowsInput) { - id + mutation($input: TerminateWorkflowsInput!) { + terminateWorkflows(input: $input) { + status } }`, pauseWorkflows: ` - mutation ($pauseWorkflowsInput: PauseWorkflowsInput!) { - pauseWorkflows(input: $pauseWorkflowsInput) { - id + mutation($input: ResumeWorkflowsInput!) { + resumeWorkflows(input: $input) { + status } }`, resumeWorkflows: ` - mutation ($resumeWorkflowsInput: ResumeWorkflowsInput!) { - resumeWorkflows(input: $resumeWorkflowsInput) { - id - } - }`, - sendEventToWorkflowByNameAndCustomId: ` - mutation ($sendEventToWorkflowByNameAndCustomIdInput: SendEventToWorkflowByNameAndCustomIdInput!) { - sendEventToWorkflowByNameAndCustomId(input: $sendEventToWorkflowByNameAndCustomIdInput) { - event { - intentId - } + mutation($input: ResumeWorkflowsInput!) { + resumeWorkflows(input: $input) { + status } }`, sendEventToWorkflows: ` - mutation ($sendEventToWorkflowsInput: SendEventToWorkflowsInput!) { - sendEventToWorkflows(input: $sendEventToWorkflowsInput) { - event { - data - input - intentId - name - } + mutation($input: SendEventToWorkflowsInput!) { + sendEventToWorkflows(input: $input) { + status } }`, - sendEventToWorkflowById: ` - mutation ($sendEventToWorkflowByIdInput: SendEventToWorkflowByIdInput!) { - sendEventToWorkflowById(input: $sendEventToWorkflowByIdInput) { - event { - intentId - } + scheduleWorkflow: ` + mutation($input: ScheduleWorkflowInput!) { + scheduleWorkflow(input: $input) { + id } }`, - createWorkflowSchedule: ` - mutation ($createWorkflowScheduleInput: CreateWorkflowScheduleInput!) { - createWorkflowSchedule(input: $createWorkflowScheduleInput) { - schedule { - id - name - cron - insertedAt - updatedAt - target { - ... on WorkflowTarget { - name - type - canonicalName - programmingLanguage - properties - codePathVersion - initialLibraryVersion - } - } - } - } - }`, - createTaskSchedule: ` - mutation ($createTaskScheduleInput: CreateTaskScheduleInput!) { - createTaskSchedule(input: $createTaskScheduleInput) { - schedule { - id - name - cron - insertedAt - updatedAt - target { - ... on TaskTarget { - name - type - programmingLanguage - properties - codePathVersion - initialLibraryVersion - } - } - } + scheduleTask: ` + mutation($input: ScheduleTaskInput!) { + scheduleTask(input: $input) { + id } - }`, + }`, }; module.exports = Alfred; From f6055efccd7fe2c88fe75e9e9949c4e18223a41c Mon Sep 17 00:00:00 2001 From: Louis Cibot Date: Tue, 14 Jan 2020 10:09:25 +0100 Subject: [PATCH 02/10] Replace input by data for sendEvent --- src/Code/serverless/Client/Alfred.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Code/serverless/Client/Alfred.js b/src/Code/serverless/Client/Alfred.js index 4023d6d..98ff8c5 100644 --- a/src/Code/serverless/Client/Alfred.js +++ b/src/Code/serverless/Client/Alfred.js @@ -205,7 +205,7 @@ const Alfred = class Alfred { appId: this.client.appId, environment: this.client.appEnv, name: eventName, - input: serializer.encode(eventData), + data: serializer.encode(eventData), selector: query, }, }; @@ -230,7 +230,7 @@ const Alfred = class Alfred { appId: this.client.appId, environment: this.client.appEnv, name: eventName, - input: serializer.encode(eventData), + data: serializer.encode(eventData), selector: { id }, }, }; From e05e4567f6b1cfe9d902dfd032945229096f0133 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Lebecq Date: Wed, 15 Jan 2020 15:57:11 +0100 Subject: [PATCH 03/10] Fix input variable name in Alfred.runTask --- src/Code/serverless/Client/Alfred.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Code/serverless/Client/Alfred.js b/src/Code/serverless/Client/Alfred.js index 98ff8c5..ed963e2 100644 --- a/src/Code/serverless/Client/Alfred.js +++ b/src/Code/serverless/Client/Alfred.js @@ -31,7 +31,7 @@ const Alfred = class Alfred { const mutation = mutations.dispatchTask; const variables = { - dispatchTaskInput: { + input: { appId: this.client.appId, environment: this.client.appEnv, name: body[ATTR_NAME], From dac91239f962960e414f4bf34df4535a6c6fd1ec Mon Sep 17 00:00:00 2001 From: Pierre-Yves Lebecq Date: Wed, 15 Jan 2020 16:13:06 +0100 Subject: [PATCH 04/10] Fix dispatch of workflow --- src/Code/serverless/Client/Alfred.js | 2 +- src/Code/serverless/Services/Versioner.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Code/serverless/Client/Alfred.js b/src/Code/serverless/Client/Alfred.js index ed963e2..7e479f8 100644 --- a/src/Code/serverless/Client/Alfred.js +++ b/src/Code/serverless/Client/Alfred.js @@ -80,7 +80,7 @@ const Alfred = class Alfred { const body = this._getBodyForWorkflow(w); const mutation = mutations.dispatchWorkflow; const variables = { - dispatchWorkflowInput: { + input: { appId: this.client.appId, environment: this.client.appEnv, name: body[ATTR_NAME], diff --git a/src/Code/serverless/Services/Versioner.js b/src/Code/serverless/Services/Versioner.js index 571f033..d776fee 100644 --- a/src/Code/serverless/Services/Versioner.js +++ b/src/Code/serverless/Services/Versioner.js @@ -5,7 +5,7 @@ const versioner = function versioner(name) { const versionMatch = name.match(versionRegex); const isVersioned = Array.isArray(versionMatch); const canonical = isVersioned ? versionMatch[1] : name; - const version = isVersioned ? parseInt(versionMatch[2], 10) : 0; + const version = isVersioned ? parseInt(versionMatch[2], 10) : null; return { canonical, version, name }; }; From 65ca89df6a12fc947fcbfcd84650f86bd6ad934f Mon Sep 17 00:00:00 2001 From: Pierre-Yves Lebecq Date: Thu, 16 Jan 2020 10:08:40 +0100 Subject: [PATCH 05/10] Fix all remaining GraphQL mutations --- src/Code/serverless/Client/Alfred.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Code/serverless/Client/Alfred.js b/src/Code/serverless/Client/Alfred.js index 7e479f8..507df7f 100644 --- a/src/Code/serverless/Client/Alfred.js +++ b/src/Code/serverless/Client/Alfred.js @@ -55,7 +55,7 @@ const Alfred = class Alfred { const body = this._getBodyForTask(task); const mutation = mutations.scheduleTask; const variables = { - scheduleTaskInput: { + input: { appId: this.client.appId, environment: this.client.appEnv, cron: task.scheduling.cron, @@ -106,7 +106,7 @@ const Alfred = class Alfred { const body = this._getBodyForWorkflow(w); const mutation = mutations.scheduleWorkflow; const variables = { - scheduleWorkflow: { + input: { appId: this.client.appId, environment: this.client.appEnv, cron: w.scheduling.cron, @@ -133,7 +133,7 @@ const Alfred = class Alfred { const mutation = mutations.terminateWorkflows; const variables = { - terminateWorkflowsInput: { + input: { appId: this.client.appId, environment: this.client.appEnv, selector: query, @@ -156,7 +156,7 @@ const Alfred = class Alfred { const endpoint = this._getGatewayUrl(); const mutation = mutations.pauseWorkflows; const variables = { - pauseWorkflowsInput: { + input: { appId: this.client.appId, environment: this.client.appEnv, selector: query, @@ -178,7 +178,7 @@ const Alfred = class Alfred { const endpoint = this._getGatewayUrl(); const mutation = mutations.resumeWorkflows; const variables = { - resumeWorkflowsInput: { + input: { appId: this.client.appId, environment: this.client.appEnv, selector: query, @@ -201,7 +201,7 @@ const Alfred = class Alfred { const mutation = mutations.sendEventToWorkflows; const variables = { - sendEventToWorkflowsInput: { + input: { appId: this.client.appId, environment: this.client.appEnv, name: eventName, @@ -226,7 +226,7 @@ const Alfred = class Alfred { const mutation = mutations.sendEventToWorkflows; const variables = { - sendEventToWorkflowsInput: { + input: { appId: this.client.appId, environment: this.client.appEnv, name: eventName, From 7bd5dd36548a2529c4050794e9a3bee496ed0b6d Mon Sep 17 00:00:00 2001 From: Pierre-Yves Lebecq Date: Thu, 16 Jan 2020 10:29:27 +0100 Subject: [PATCH 06/10] Fix selector module for new graphql api --- src/Code/serverless/Client/Select.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Code/serverless/Client/Select.js b/src/Code/serverless/Client/Select.js index 5a8889d..531d1d2 100644 --- a/src/Code/serverless/Client/Select.js +++ b/src/Code/serverless/Client/Select.js @@ -11,7 +11,6 @@ const Select = class Select { `In "select.workflow()", parameter should be a string - not a "${typeof name}"`, ); } - this._type = "WORKFLOW"; this._name = name; return this; @@ -93,9 +92,8 @@ const Select = class Select { _getQuery() { return { - type: this._type, name: this._name, - customId: this._customId, + tag: this._customId, id: this._instanceIntentId, }; } From 92470b63f7335c1b053212d2aae19907b3b57e19 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Lebecq Date: Thu, 16 Jan 2020 10:50:18 +0100 Subject: [PATCH 07/10] Fix pause workflows mutation --- src/Code/serverless/Client/Alfred.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Code/serverless/Client/Alfred.js b/src/Code/serverless/Client/Alfred.js index 507df7f..141dc69 100644 --- a/src/Code/serverless/Client/Alfred.js +++ b/src/Code/serverless/Client/Alfred.js @@ -366,8 +366,8 @@ const mutations = { } }`, pauseWorkflows: ` - mutation($input: ResumeWorkflowsInput!) { - resumeWorkflows(input: $input) { + mutation($input: PauseWorkflowsInput!) { + pauseWorkflows(input: $input) { status } }`, From fbc0a58f63db1456ff620d918a0416a53faaf4a7 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Lebecq Date: Fri, 17 Jan 2020 10:23:39 +0100 Subject: [PATCH 08/10] Change versioner module to use strings for versions --- src/Code/serverless/Services/Versioner.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Code/serverless/Services/Versioner.js b/src/Code/serverless/Services/Versioner.js index d776fee..b70ebff 100644 --- a/src/Code/serverless/Services/Versioner.js +++ b/src/Code/serverless/Services/Versioner.js @@ -1,11 +1,11 @@ // version must be structured as (canonical)_v(number) -const versionRegex = /^(.+)_v(\d+)$/; +const versionRegex = /^(.+)_(v\d+)$/; const versioner = function versioner(name) { const versionMatch = name.match(versionRegex); const isVersioned = Array.isArray(versionMatch); const canonical = isVersioned ? versionMatch[1] : name; - const version = isVersioned ? parseInt(versionMatch[2], 10) : null; + const version = isVersioned ? versionMatch[2] : null; return { canonical, version, name }; }; From 37d4f317bd9449bd6b2a9b7713d912e4ede1b768 Mon Sep 17 00:00:00 2001 From: Louis Cibot Date: Fri, 17 Jan 2020 12:07:43 +0100 Subject: [PATCH 09/10] fix job contains a null ID --- src/Code/serverless/Client/Alfred.js | 63 ++++++++-------------------- 1 file changed, 17 insertions(+), 46 deletions(-) diff --git a/src/Code/serverless/Client/Alfred.js b/src/Code/serverless/Client/Alfred.js index 141dc69..7b70c04 100644 --- a/src/Code/serverless/Client/Alfred.js +++ b/src/Code/serverless/Client/Alfred.js @@ -1,6 +1,5 @@ const { GraphQLClient } = require("graphql-request"); const { serializer, versioner } = require("../Services"); -const Job = require("./Job"); const { ExternalZenatonError, InternalZenatonError, @@ -38,13 +37,10 @@ const Alfred = class Alfred { input: body[ATTR_INPUT], }, }; - const job = new Job(); - const promise = this._request(endpoint, mutation, variables).then( + + return this._request(endpoint, mutation, variables).then( (res) => res.dispatchTask, ); - job.promise = promise; - - return job; } /** @@ -63,13 +59,10 @@ const Alfred = class Alfred { input: body[ATTR_INPUT], }, }; - const job = new Job(); - const promise = this._request(endpoint, mutation, variables).then( + + return this._request(endpoint, mutation, variables).then( (res) => res.createTaskSchedule, ); - job.promise = promise; - - return job; } /** @@ -89,13 +82,10 @@ const Alfred = class Alfred { version: body[ATTR_VERSION], }, }; - const job = new Job(); - const promise = this._request(endpoint, mutation, variables).then( + + return this._request(endpoint, mutation, variables).then( (res) => res.dispatchWorkflow, ); - job.promise = promise; - - return job; } /** @@ -116,13 +106,10 @@ const Alfred = class Alfred { version: body[ATTR_VERSION], }, }; - const job = new Job(); - const promise = this._request(endpoint, mutation, variables).then( + + return this._request(endpoint, mutation, variables).then( (res) => res.scheduleWorkflow, ); - job.promise = promise; - - return job; } /** @@ -140,13 +127,9 @@ const Alfred = class Alfred { }, }; - const job = new Job(); - const promise = this._request(endpoint, mutation, variables).then( + return this._request(endpoint, mutation, variables).then( (res) => res.killWorkflows, ); - job.promise = promise; - - return job; } /** @@ -162,13 +145,10 @@ const Alfred = class Alfred { selector: query, }, }; - const job = new Job(); - const promise = this._request(endpoint, mutation, variables).then( + + return this._request(endpoint, mutation, variables).then( (res) => res.pauseWorkflows, ); - job.promise = promise; - - return job; } /** @@ -184,13 +164,10 @@ const Alfred = class Alfred { selector: query, }, }; - const job = new Job(); - const promise = this._request(endpoint, mutation, variables).then( + + return this._request(endpoint, mutation, variables).then( (res) => res.resumeWorkflows, ); - job.promise = promise; - - return job; } /** @@ -209,13 +186,10 @@ const Alfred = class Alfred { selector: query, }, }; - const job = new Job(); - const promise = this._request(endpoint, mutation, variables).then( + + return this._request(endpoint, mutation, variables).then( (res) => res.sendEventToWorkflows, ); - job.promise = promise; - - return job; } /** @@ -234,13 +208,10 @@ const Alfred = class Alfred { selector: { id }, }, }; - const job = new Job(); - const promise = this._request(endpoint, mutation, variables).then( + + return this._request(endpoint, mutation, variables).then( (res) => res.sendEventToWorkflows, ); - job.promise = promise; - - return job; } _getGatewayUrl() { From 26126b34b3ff6e393ff9ce8eb17861279287047c Mon Sep 17 00:00:00 2001 From: Pierre-Yves Lebecq Date: Mon, 20 Jan 2020 12:33:22 +0100 Subject: [PATCH 10/10] Remove workflow name when selecting self --- src/Code/serverless/Decider/Workflow.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Code/serverless/Decider/Workflow.js b/src/Code/serverless/Decider/Workflow.js index 8821b7a..65ebb48 100644 --- a/src/Code/serverless/Decider/Workflow.js +++ b/src/Code/serverless/Decider/Workflow.js @@ -169,7 +169,7 @@ const workflow = function workflow(name, definition) { } _selectSelf() { - return new Select(this._processor).workflow(name).withId(this.context.id); + return new Select(this._processor).workflow().withId(this.context.id); } };