Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 20, 2025

This PR introduces the new Serviz::Workflow class that allows composing multiple Serviz service objects together using a clean, declarative DSL, addressing the need for orchestrating complex multi-step operations.

New Features

The Serviz::Workflow class inherits from Serviz::Base and provides:

  • Declarative step definition using class-level step method declarations
  • Conditional execution using the if: option to control whether steps run based on previous results
  • Error accumulation from all failed steps in the workflow
  • Result chaining where the last successful step's result becomes the workflow result
  • Full compatibility with the existing Serviz interface (success?, failure?, errors, result)

Usage Example

class UserOnboarding < Serviz::Workflow
  step RegisterUser
  step SendWelcomeEmail, if: ->(result) { result.success? }
  step LogOnboardingService
end

# Usage
result = UserOnboarding.call(user_params)
puts result.success? # => true
puts result.result   # => result from LogOnboardingService

# Handles failures gracefully
result = UserOnboarding.call(invalid_params)
puts result.failure? # => true
puts result.errors   # => ["Registration failed"]

Advanced Usage with Custom Parameters

class OrderProcessing < Serviz::Workflow
  step ValidateOrder
  step ChargePayment, params: { gateway: 'stripe' }, if: ->(result) { result.success? }
  step ShipOrder, if: ->(result) { result.success? }
end

Copy link
Contributor Author

Copilot AI commented Aug 20, 2025

@markets 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Co-authored-by: markets <576701+markets@users.noreply.github.com>
Copilot AI changed the title [WIP] New Serviz::Workflow class to run multiple Serviz instances encapsulated Add Serviz::Workflow class to compose multiple services in a pipeline Aug 20, 2025
Copilot AI requested a review from markets August 20, 2025 13:36
@markets
Copy link
Owner

markets commented Aug 20, 2025

@copilot Let's change this a bit. New DSL:

class UserOnboarding < Serviz::Workflow
  step RegisterUser
  step SendWelcomeEmail, if: ->(result) { result.success? }
  step LogOnboardingService
end

result = UserOnboarding.call(user_params)

…` class method

Implemented new DSL as requested:
- Replace `run` method calls in `call` method with class-level `step` declarations
- Maintain support for `params:` and `if:` options in `step` method
- Support both static params and proc-based params for dynamic evaluation
- Automatically execute all defined steps in `call` method
- Update SampleWorkflow and all tests to use new DSL
- Maintain full backward compatibility with Serviz::Base interface

Co-authored-by: markets <576701+markets@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 20, 2025

@copilot Let's change this a bit. New DSL:

...

Done! I've implemented the new declarative DSL as requested. The workflow now uses class-level step declarations instead of imperative run calls in the call method.

The new syntax works exactly as shown in your example:

class UserOnboarding < Serviz::Workflow
  step RegisterUser
  step SendWelcomeEmail, if: ->(result) { result.success? }
  step LogOnboardingService
end

All existing functionality is preserved including params: and if: options, error accumulation, and result chaining. Updated all tests and the SampleWorkflow to use the new DSL.

Commit: fa68f66

Copilot AI changed the title Add Serviz::Workflow class to compose multiple services in a pipeline Add Serviz::Workflow class with declarative step-based DSL for composing multiple services Aug 20, 2025
@markets
Copy link
Owner

markets commented Aug 25, 2025

@copilot

  • update from master (relevant commit: 1f33ff3)
  • update docs (README) too
  • more the require 'serviz/workflow' at the beginning of the file
  • remove the SampleWorkflow sceneario and their associated tests

…ve SampleWorkflow

Co-authored-by: markets <576701+markets@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 25, 2025

@copilot

  • update from master (relevant commit: 1f33ff3)
  • update docs (README) too
    ...

All requested changes have been implemented:

  • Updated from master with argument forwarding operator (...) changes
  • Moved require 'serviz/workflow' to after Base class definition (to avoid circular dependency)
  • Updated README with comprehensive Workflow documentation and examples
  • Removed SampleWorkflow scenario and associated tests

Commit: e08c3ce

@markets markets marked this pull request as ready for review August 25, 2025 14:36
@markets markets merged commit 4b0eff2 into master Aug 25, 2025
7 checks passed
@markets markets deleted the copilot/fix-7 branch August 25, 2025 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants