11const uuidv4 = require ( "uuid/v4" ) ;
22const workflowManager = require ( "./Workflows/WorkflowManager" ) ;
33const http = require ( "./Services/Http" ) ;
4+ const graphQL = require ( "./Services/GraphQL" ) ;
45const serializer = require ( "./Services/Serializer" ) ;
56const { version } = require ( "../infos" ) ;
67const { init, credentials } = require ( "../client" ) ;
@@ -10,6 +11,8 @@ const ZENATON_WORKER_URL = "http://localhost";
1011const DEFAULT_WORKER_PORT = 4001 ;
1112const WORKER_API_VERSION = "v_newton" ;
1213
14+ const ZENATON_GATEWAY_URL = "https://gateway.zenaton.com/api" ;
15+
1316const APP_ENV = "app_env" ;
1417const APP_ID = "app_id" ;
1518const API_TOKEN = "api_token" ;
@@ -25,7 +28,6 @@ const ATTR_INITIAL_LIB_VERSION = "initial_library_version";
2528const ATTR_CODE_PATH_VERSION = "code_path_version" ;
2629const ATTR_MODE = "mode" ;
2730const ATTR_MAX_PROCESSING_TIME = "maxProcessingTime" ;
28- const ATTR_SCHEDULING_CRON = "scheduling_cron" ;
2931
3032const PROG = "Javascript" ;
3133const INITIAL_LIB_VERSION = version ;
@@ -113,6 +115,14 @@ module.exports = class Client {
113115 return `${ host } ${ path } ` ;
114116 }
115117
118+ getGatewayUrl ( ) {
119+ const host = process . env . ZENATON_GATEWAY_URL
120+ ? process . env . ZENATON_GATEWAY_URL
121+ : ZENATON_GATEWAY_URL ;
122+
123+ return host ;
124+ }
125+
116126 /**
117127 * Start a task instance
118128 */
@@ -136,19 +146,24 @@ module.exports = class Client {
136146 }
137147
138148 async startScheduledTask ( task ) {
139- const url = this . getWorkerUrlNew ( "scheduling/tasks" ) ;
140-
141- // schedule task
142- const body = this . getBodyForTask ( task ) ;
143-
144- const params = Object . assign (
145- {
146- [ ATTR_SCHEDULING_CRON ] : task . scheduling . cron ,
149+ const endpoint = this . getGatewayUrl ( ) ;
150+ const taskBody = this . getBodyForTask ( task ) ;
151+ const mutation = graphQL . mutations . createTaskSchedule ;
152+ const variables = {
153+ createTaskScheduleInput : {
154+ intentId : taskBody [ ATTR_INTENT_ID ] ,
155+ environmentName : credentials . appEnv ,
156+ cron : task . scheduling . cron ,
157+ taskName : taskBody [ ATTR_NAME ] ,
158+ programmingLanguage : taskBody [ ATTR_PROG ] . toUpperCase ( ) ,
159+ properties : taskBody [ ATTR_DATA ] ,
160+ codePathVersion : taskBody [ ATTR_CODE_PATH_VERSION ] ,
161+ initialLibraryVersion : taskBody [ ATTR_INITIAL_LIB_VERSION ] ,
147162 } ,
148- this . getAppEnv ( ) ,
149- ) ;
163+ } ;
150164
151- return http . post ( url , body , { params } ) ;
165+ const res = await graphQL . request ( endpoint , mutation , variables ) ;
166+ return res . createTaskSchedule ;
152167 }
153168
154169 /**
@@ -174,19 +189,25 @@ module.exports = class Client {
174189 }
175190
176191 async startScheduledWorkflow ( flow ) {
177- const url = this . getWorkerUrlNew ( "scheduling/instances" ) ;
178-
179- // schedule workflow
180- const body = this . getBodyForWorkflow ( flow ) ;
181-
182- const params = Object . assign (
183- {
184- [ ATTR_SCHEDULING_CRON ] : flow . scheduling . cron ,
192+ const endpoint = this . getGatewayUrl ( ) ;
193+ const workflowBody = this . getBodyForWorkflow ( flow ) ;
194+ const mutation = graphQL . mutations . createWorkflowSchedule ;
195+ const variables = {
196+ createWorkflowScheduleInput : {
197+ intentId : workflowBody [ ATTR_INTENT_ID ] ,
198+ environmentName : credentials . appEnv ,
199+ cron : flow . scheduling . cron ,
200+ workflowName : workflowBody [ ATTR_NAME ] ,
201+ canonicalName : workflowBody [ ATTR_CANONICAL ] || workflowBody [ ATTR_NAME ] ,
202+ programmingLanguage : workflowBody [ ATTR_PROG ] . toUpperCase ( ) ,
203+ properties : workflowBody [ ATTR_DATA ] ,
204+ codePathVersion : workflowBody [ ATTR_CODE_PATH_VERSION ] ,
205+ initialLibraryVersion : workflowBody [ ATTR_INITIAL_LIB_VERSION ] ,
185206 } ,
186- this . getAppEnv ( ) ,
187- ) ;
207+ } ;
188208
189- return http . post ( url , body , { params } ) ;
209+ const res = await graphQL . request ( endpoint , mutation , variables ) ;
210+ return res . createWorkflowSchedule ;
190211 }
191212
192213 /**
0 commit comments