Skip to content

Add Workflow step decorator - #224

Merged
seratch merged 3 commits into
slackapi:mainfrom
seratch:step-decorator
Jan 27, 2021
Merged

seratch merged 3 commits into
slackapi:mainfrom
seratch:step-decorator

Conversation

@seratch

@seratch seratch commented Jan 27, 2021

Copy link
Copy Markdown
Contributor

Rebasing #113 towards the latest main branch was so hard that I came up with a new branch with the same changes. @mwbrooks already gave LGTM to #113


This pull request adds Workflow Steps support using decorator interface. This way provides more Pythonic way of coding and more flexibility for workflow step listeners. Adding this feature doesn't break anything for the default way to add steps to Bolt apps.

app = App()
copy_review_step = WorkflowStep.builder("copy_review")

@copy_review_step.edit
def edit(ack: Ack, step, configure: Configure):
    ack()
    configure(blocks=[])

@copy_review_step.save
def save(ack: Ack, step: dict, view: dict, update: Update):
    state_values = view["state"]["values"]
    update(inputs={}, outputs=[])
    ack()

def additional_matcher(step):
    return True

def noop_middleware(next):
    return next()

def notify_execution(client: WebClient, step: dict):
    time.sleep(5)
    client.chat_postMessage(channel="#random", text=f"Step execution: ```{step}```")

@copy_review_step.execute(
    matchers=[additional_matcher],
    middleware=[noop_middleware],
    lazy=[notify_execution],
)
def execute(step: dict, client: WebClient, complete: Complete, fail: Fail):
    try:
        complete(outputs={})
    except Exception as err:
        fail(error={"message": f"Something wrong! {err}"})

app.step(copy_review_step)

Category (place an x in each of the [ ])

  • slack_bolt.App and/or its core components
  • slack_bolt.async_app.AsyncApp and/or its core components
  • Adapters in slack_bolt.adapter
  • Document pages under /docs
  • Others

Requirements (place an x in each [ ])

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've run ./scripts/install_all_and_run_tests.sh after making the changes.

@seratch seratch added this to the 1.3.0 milestone Jan 27, 2021
@seratch seratch self-assigned this Jan 27, 2021
@seratch seratch mentioned this pull request Jan 27, 2021
5 of 8 tasks
@codecov

codecov Bot commented Jan 27, 2021 •

Copy link
Copy Markdown

Codecov Report

Merging #224 (243dd37) into main (6ce7bdc) will decrease coverage by 0.23%.
The diff coverage is 86.23%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #224      +/-   ##
==========================================
- Coverage   91.59%   91.36%   -0.24%     
==========================================
  Files         159      160       +1     
  Lines        4772     4967     +195     
==========================================
+ Hits         4371     4538     +167     
- Misses        401      429      +28     
Impacted Files Coverage Δ
slack_bolt/app/app.py 86.88% <75.00%> (+0.10%) ⬆️
slack_bolt/app/async_app.py 94.73% <75.00%> (+0.03%) ⬆️
slack_bolt/workflows/step/step.py 88.88% <86.44%> (-5.23%) ⬇️
slack_bolt/workflows/step/async_step.py 88.95% <86.55%> (-5.25%) ⬇️
slack_bolt/workflows/step/internals.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6ce7bdc...243dd37. Read the comment docs.

@seratch
seratch merged commit ab96196 into slackapi:main Jan 27, 2021
@seratch
seratch deleted the step-decorator branch January 27, 2021 23:09
@seratch seratch mentioned this pull request Feb 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants