Skip to content

Commit

Permalink
refactor: rely on existing workflowactionsteps in seed_workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstankiewicz committed Oct 1, 2024
1 parent d6149c8 commit 059dca2
Showing 1 changed file with 22 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
WorkflowItemThrough,
WorkflowStepGroup
)
from enterprise_access.apps.workflows.registry import WorkflowActionRegistry

logger = logging.getLogger(__name__)

Expand All @@ -31,37 +32,18 @@ def handle(self, *args, **kwargs): # pylint: disable=unused-argument
)
logger.info(f'Created WorkflowDefinition: {workflow_definition.name}')

# Example: Adding WorkflowActionSteps
step_activate_enterprise_customer_user, _ = WorkflowActionStep.objects.get_or_create(
name="Activate Enterprise Customer User",
action_reference="enterprise_access.apps.workflows.handlers.activate_enterprise_customer_user"
)
step_activate_subsciption_license, _ = WorkflowActionStep.objects.get_or_create(
name="Activate Subscription License",
action_reference="enterprise_access.apps.workflows.handlers.activate_subscription_license"
)
step_auto_apply_subscription_license, _ = WorkflowActionStep.objects.get_or_create(
name="Auto-apply Subscription License",
action_reference="enterprise_access.apps.workflows.handlers.auto_apply_subscription_license"
)
step_retrieve_subscription_licenses, _ = WorkflowActionStep.objects.get_or_create(
name="Retrieve Subscription Licenses",
action_reference="enterprise_access.apps.workflows.handlers.retrieve_subscription_licenses"
)
step_retrieve_credits_available, _ = WorkflowActionStep.objects.get_or_create(
name="Retrieve Credits Available",
action_reference="enterprise_access.apps.workflows.handlers.retrieve_credits_available"
)
step_enroll_default_enterprise_course_enrollments, _ = WorkflowActionStep.objects.get_or_create(
name="Enroll Default Enterprise Course Enrollments",
action_reference="enterprise_access.apps.workflows.handlers.enroll_default_enterprise_course_enrollments"
)
step_retrieve_enterprise_course_enrollments, _ = WorkflowActionStep.objects.get_or_create(
name="Retrieve Enterprise Course Enrollments",
action_reference="enterprise_access.apps.workflows.handlers.retrieve_enterprise_course_enrollments"
)
# Get all registered slugs from the registry
registry_actions = WorkflowActionRegistry.list_actions()

logger.info('Created WorkflowActionSteps')
steps = {}
for slug, _ in registry_actions:
try:
steps[slug] = WorkflowActionStep.objects.get(action_reference=slug)
except WorkflowActionStep.DoesNotExist:
logger.error(
f"WorkflowActionStep with action_reference '{slug}' not found. Ensure it is registered properly."
)
logger.info('Validated WorkflowActionSteps from registered actions in the WorkflowActionRegistry.')

# Example: Adding WorkflowStepGroup (retrieve subsidies)
group_retrieve_subsidies, _ = WorkflowStepGroup.objects.get_or_create(
Expand All @@ -70,12 +52,12 @@ def handle(self, *args, **kwargs): # pylint: disable=unused-argument
)
WorkflowGroupActionStepThrough.objects.get_or_create(
step_group=group_retrieve_subsidies,
step=step_retrieve_subscription_licenses,
step=steps.get('retrieve_subscription_licenses'),
defaults={'order': 0},
)
WorkflowGroupActionStepThrough.objects.get_or_create(
step_group=group_retrieve_subsidies,
step=step_retrieve_credits_available,
step=steps.get('retrieve_credits_available'),
defaults={'order': 1},
)

Expand All @@ -86,17 +68,17 @@ def handle(self, *args, **kwargs): # pylint: disable=unused-argument
)
WorkflowGroupActionStepThrough.objects.get_or_create(
step_group=group_ensure_activated_subscription_license,
step=step_retrieve_subscription_licenses,
step=steps.get('retrieve_subscription_licenses'),
defaults={'order': 0},
)
WorkflowGroupActionStepThrough.objects.get_or_create(
step_group=group_ensure_activated_subscription_license,
step=step_activate_subsciption_license,
step=steps.get('activate_subscription_license'),
defaults={'order': 1},
)
WorkflowGroupActionStepThrough.objects.get_or_create(
step_group=group_ensure_activated_subscription_license,
step=step_auto_apply_subscription_license,
step=steps.get('auto_apply_subscription_license'),
defaults={'order': 2},
)

Expand All @@ -112,16 +94,16 @@ def handle(self, *args, **kwargs): # pylint: disable=unused-argument
)
WorkflowGroupActionStepThrough.objects.get_or_create(
step_group=group_retrieve_learner_portal_metadata,
step=step_retrieve_enterprise_course_enrollments,
step=steps.get('retrieve_enterprise_course_enrollments'),
defaults={'order': 1},
)

logger.info('Created WorkflowStepGroups and associated sub-steps')
logger.info('Created WorkflowStepGroups and added WorkflowActionSteps to the groups.')

# Example: Add the WorkflowActionSteps and WorkflowStepGroups to the WorkflowDefinition
WorkflowItemThrough.objects.get_or_create(
workflow_definition=workflow_definition,
action_step=step_activate_enterprise_customer_user,
action_step=steps.get('activate_enterprise_customer_user'),
defaults={'order': 0},
)
WorkflowItemThrough.objects.get_or_create(
Expand All @@ -131,7 +113,7 @@ def handle(self, *args, **kwargs): # pylint: disable=unused-argument
)
WorkflowItemThrough.objects.get_or_create(
workflow_definition=workflow_definition,
action_step=step_enroll_default_enterprise_course_enrollments,
action_step=steps.get('enroll_default_enterprise_course_enrollments'),
defaults={'order': 2},
)
WorkflowItemThrough.objects.get_or_create(
Expand All @@ -142,4 +124,4 @@ def handle(self, *args, **kwargs): # pylint: disable=unused-argument

logger.info('Added WorkflowActionSteps and WorkflowStepGroups to the WorkflowDefinition')

logger.info('Result: Successfully seeded a test workflow!')
logger.info('Successfully seeded a test workflow.')

0 comments on commit 059dca2

Please sign in to comment.