changes
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
777
app/payment.py
777
app/payment.py
File diff suppressed because it is too large
Load Diff
@@ -5,12 +5,12 @@ from app.workflow_utils import resolve_value
|
|||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def execute_step(step: StepAction, context: dict):
|
def execute_step(step: StepAction, context: dict):
|
||||||
print(f"\n>>> EXECUTING STEP: {step.step_code} (Order: {step.order})")
|
#print(f"\n>>> EXECUTING STEP: {step.step_code} (Order: {step.order})")
|
||||||
|
|
||||||
# Evaluate rules first
|
# Evaluate rules first
|
||||||
for rule in step.rules.filter(is_active=True):
|
for rule in step.rules.filter(is_active=True):
|
||||||
if not evaluate_rule(rule, context):
|
if not evaluate_rule(rule, context):
|
||||||
print(f"Step {step.step_code} skipped due to rule failure.")
|
#print(f"Step {step.step_code} skipped due to rule failure.")
|
||||||
return {"step": step.step_code, "skipped": True, "reason": "rule_failed"}
|
return {"step": step.step_code, "skipped": True, "reason": "rule_failed"}
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
@@ -21,10 +21,10 @@ def execute_step(step: StepAction, context: dict):
|
|||||||
action_type = action.get("type")
|
action_type = action.get("type")
|
||||||
params = action.get("params", {})
|
params = action.get("params", {})
|
||||||
|
|
||||||
print(f" - Action Type: {action_type}")
|
#print(f" - Action Type: {action_type}")
|
||||||
|
|
||||||
if action_type not in ACTION_REGISTRY:
|
if action_type not in ACTION_REGISTRY:
|
||||||
print(f" - ERROR: Action type '{action_type}' not registered!")
|
#print(f" - ERROR: Action type '{action_type}' not registered!")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -39,7 +39,7 @@ def execute_step(step: StepAction, context: dict):
|
|||||||
# Lưu output cuối cùng vào context
|
# Lưu output cuối cùng vào context
|
||||||
context["last_result"] = output
|
context["last_result"] = output
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f" - ERROR in action {action_type}: {str(e)}")
|
#print(f" - ERROR in action {action_type}: {str(e)}")
|
||||||
# Raise để transaction.atomic rollback nếu cần, hoặc xử lý tùy ý
|
# Raise để transaction.atomic rollback nếu cần, hoặc xử lý tùy ý
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ def evaluate_rule(rule: Rule, context: dict):
|
|||||||
right = resolve_value(condition.get("right"), context)
|
right = resolve_value(condition.get("right"), context)
|
||||||
op = condition.get("operator", "==")
|
op = condition.get("operator", "==")
|
||||||
|
|
||||||
print(f" Evaluating Rule: {left} {op} {right}")
|
#print(f" Evaluating Rule: {left} {op} {right}")
|
||||||
|
|
||||||
if op == "IN" and left not in right: return False
|
if op == "IN" and left not in right: return False
|
||||||
if op == "==" and left != right: return False
|
if op == "==" and left != right: return False
|
||||||
@@ -64,21 +64,21 @@ def evaluate_rule(rule: Rule, context: dict):
|
|||||||
|
|
||||||
|
|
||||||
def run_workflow(workflow_code: str, trigger: str, context: dict):
|
def run_workflow(workflow_code: str, trigger: str, context: dict):
|
||||||
print(f"\n================ START WORKFLOW: {workflow_code} ================")
|
#print(f"\n================ START WORKFLOW: {workflow_code} ================")
|
||||||
print(f"Trigger: {trigger} | Initial Context: {context}")
|
#print(f"Trigger: {trigger} | Initial Context: {context}")
|
||||||
|
|
||||||
workflow = Workflow.objects.filter(code=workflow_code, is_active=True).first()
|
workflow = Workflow.objects.filter(code=workflow_code, is_active=True).first()
|
||||||
if not workflow:
|
if not workflow:
|
||||||
print(f"Workflow '{workflow_code}' not found or inactive.")
|
#print(f"Workflow '{workflow_code}' not found or inactive.")
|
||||||
raise Exception(f"Workflow '{workflow_code}' not found")
|
raise Exception(f"Workflow '{workflow_code}' not found")
|
||||||
|
|
||||||
steps = workflow.steps.filter(trigger_event=trigger, is_active=True).order_by("order")
|
steps = workflow.steps.filter(trigger_event=trigger, is_active=True).order_by("order")
|
||||||
print(f"Found {steps.count()} active steps.")
|
#print(f"Found {steps.count()} active steps.")
|
||||||
|
|
||||||
outputs = []
|
outputs = []
|
||||||
for step in steps:
|
for step in steps:
|
||||||
res = execute_step(step, context)
|
res = execute_step(step, context)
|
||||||
outputs.append(res)
|
outputs.append(res)
|
||||||
|
|
||||||
print(f"================ FINISH WORKFLOW: {workflow_code} ================\n")
|
#print(f"================ FINISH WORKFLOW: {workflow_code} ================\n")
|
||||||
return outputs
|
return outputs
|
||||||
BIN
static/files/20260210100326-entry.xlsx
Normal file
BIN
static/files/20260210100326-entry.xlsx
Normal file
Binary file not shown.
Reference in New Issue
Block a user