1
+ import json
1
2
from calendar import timegm
2
3
from datetime import datetime
3
4
import pickle
20
21
from kairon .actions .definitions .base import ActionsBase
21
22
from kairon .events .executors .factory import ExecutorFactory
22
23
from kairon .exceptions import AppException
23
- from kairon .shared .actions .data_objects import ActionServerLogs , ScheduleAction
24
+ from kairon .shared .actions .data_objects import ActionServerLogs , ScheduleAction , ScheduleActionType
24
25
from kairon .shared .actions .exception import ActionFailure
25
26
from kairon .shared .actions .models import ActionType
26
27
from kairon .shared .actions .utils import ActionUtility
27
28
from kairon .shared .callback .data_objects import CallbackConfig
29
+ from kairon .shared .constants import EventClass
28
30
from kairon .shared .data .constant import TASK_TYPE
29
31
30
32
@@ -78,7 +80,8 @@ async def execute(self, dispatcher: CollectingDispatcher, tracker: Tracker, doma
78
80
schedule_action = None
79
81
schedule_time = None
80
82
timezone = None
81
- pyscript_code = None
83
+ execution_info = None
84
+ event_data = None
82
85
try :
83
86
action_config = self .retrieve_config ()
84
87
dispatch_bot_response = action_config .get ('dispatch_bot_response' , True )
@@ -87,8 +90,6 @@ async def execute(self, dispatcher: CollectingDispatcher, tracker: Tracker, doma
87
90
tracker_data .update ({'bot' : self .bot })
88
91
schedule_action = action_config ['schedule_action' ]
89
92
timezone = action_config ['timezone' ]
90
- callback = CallbackConfig .get_entry (name = schedule_action , bot = self .bot )
91
- pyscript_code = callback ['pyscript_code' ]
92
93
schedule_time , _ = ActionUtility .get_parameter_value (tracker_data ,
93
94
action_config ['schedule_time' ],
94
95
self .bot )
@@ -98,12 +99,35 @@ async def execute(self, dispatcher: CollectingDispatcher, tracker: Tracker, doma
98
99
action_config ['params_list' ],
99
100
self .bot )
100
101
logger .info ("schedule_data: " + str (schedule_data_log ))
101
- event_data = {'data' : {'source_code' : callback ['pyscript_code' ],
102
- 'predefined_objects' : schedule_data
103
- },
104
- 'date_time' : date_parser .parse (schedule_time ),
105
- 'timezone' : action_config ['timezone' ]
106
- }
102
+
103
+ if action_config ['schedule_action_type' ] == ScheduleActionType .PYSCRIPT .value :
104
+ callback = CallbackConfig .get_entry (name = schedule_action , bot = self .bot )
105
+ event_data = {'data' : {'source_code' : callback ['pyscript_code' ],
106
+ 'predefined_objects' : schedule_data
107
+ },
108
+ 'date_time' : date_parser .parse (schedule_time ),
109
+ 'timezone' : action_config ['timezone' ]
110
+ }
111
+ execution_info = {
112
+ 'pyscript_code' : callback ['pyscript_code' ],
113
+ 'type' : ScheduleActionType .PYSCRIPT .value
114
+ }
115
+ elif action_config ['schedule_action_type' ] == ScheduleActionType .FLOW .value :
116
+ event_data = {
117
+ 'data' : {
118
+ 'slot_data' : json .dumps (schedule_data ),
119
+ 'flow_name' : schedule_action ,
120
+ 'bot' : self .bot ,
121
+ 'user' : tracker .sender_id
122
+ },
123
+ 'date_time' : date_parser .parse (schedule_time ),
124
+ 'timezone' : action_config ['timezone' ],
125
+ 'is_flow' : True
126
+ }
127
+ execution_info = {
128
+ 'flow' : schedule_action ,
129
+ 'type' : ScheduleActionType .FLOW .value
130
+ }
107
131
await self .add_schedule_job (** event_data )
108
132
except Exception as e :
109
133
exception = e
@@ -128,7 +152,7 @@ async def execute(self, dispatcher: CollectingDispatcher, tracker: Tracker, doma
128
152
schedule_action = schedule_action ,
129
153
schedule_time = schedule_time ,
130
154
timezone = timezone ,
131
- pyscript_code = pyscript_code ,
155
+ execution_info = execution_info ,
132
156
data = schedule_data_log
133
157
).save ()
134
158
return {}
@@ -137,13 +161,19 @@ async def add_schedule_job(self,
137
161
date_time : datetime ,
138
162
data : Dict ,
139
163
timezone : Text ,
164
+ is_flow = False ,
140
165
** kwargs ):
141
166
func = obj_to_ref (ExecutorFactory .get_executor ().execute_task )
142
167
143
168
_id = uuid7 ().hex
144
- data ['predefined_objects' ]['event' ] = _id
145
169
args = (func , "scheduler_evaluator" , data ,)
146
- kwargs .update ({'task_type' : TASK_TYPE .ACTION .value })
170
+ if is_flow :
171
+ args = (ExecutorFactory .get_executor (), EventClass .agentic_flow , data ,)
172
+ kwargs .update ({'task_type' : TASK_TYPE .EVENT .value })
173
+ else :
174
+ kwargs .update ({'task_type' : TASK_TYPE .ACTION .value })
175
+ data ['predefined_objects' ]['event' ] = _id
176
+
147
177
trigger = DateTrigger (run_date = date_time , timezone = timezone )
148
178
149
179
next_run_time = trigger .get_next_fire_time (None , datetime .now (astimezone (timezone ) or get_localzone ()))
0 commit comments