Skip to content
This repository has been archived by the owner on Feb 8, 2025. It is now read-only.

feat: add ability to manage date based flows #1025

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft

Conversation

djaiss
Copy link
Member

@djaiss djaiss commented Jun 10, 2021

This will be a very complex PR.

There are two types of flows:

  1. flows based on dates, like hiring date,
  2. flows based on events, like if a project changes.

This PR covers the first use case: date based flows.


How does this work?

A flow is about either a date, or an event that happens in the account.
Let's take the example of the hiring date.
So we define a flow about the hiring date. This means: when the hiring date happens, do "something".

When we define a flow about a date, we have two options:

  1. either execute the flow when the date is met, then stop executing it.
  2. execute the flow on the anniversary of the date. In this case, every time the date is met each year, the flow will replay.

Flows are made of steps. Each step can have one or more actions. Actions are things like send an email, create a task, lend an asset,...

"Date based" flows can have steps that can be executed before, during or after the event occurs, like "3 weeks before, do this", or "2 days after, do this".

Flows are always associated with a trigger type, like Flow::TRIGGER_HIRING_DATE, that defines which criteria will trigger the flow.

When should flows run

A flow will run in two cases:

  • once a flow has been defined and started,
  • if an object, like Employee, is modified.

How does OfficeLife deal with flows

When a flow runs, it:

  • checks all the steps, and for each step, checks all the actions
  • for each action, it creates a ScheduledAction object which will have a trigger date that matches the date defined in the step (three weeks before, for instance).
  • we have a job ProcessAllScheduledActions, that is executed every hour, which will check if we should process a scheduled action in the current hour.
  • if that's the case, the scheduled action is executed, and we check if the flow is about the anniversary of the trigger date, or not. If it's an anniversary, we will schedule the next ScheduledAction on the next anniversary of the date.

And that's it.

@djaiss djaiss changed the title feat: add ability to manage flows feat: add ability to manage date based flows Jun 10, 2021
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 3 Code Smells

52.1% 52.1% Coverage
5.3% 5.3% Duplication

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant