Skip to content

Initial draft of composable timetables#28757

Closed
collinmcnulty wants to merge 2 commits intoapache:mainfrom
collinmcnulty:composable-timetables
Closed

Initial draft of composable timetables#28757
collinmcnulty wants to merge 2 commits intoapache:mainfrom
collinmcnulty:composable-timetables

Conversation

@collinmcnulty
Copy link
Contributor

Given that timetables vary across multiple dimensions, I believe they are a good candidate for composition over inheritance. For instance, the CronTriggerTimetable is great, but it's easy to imagine wanting a variety of different data intervals other than a fixed timedelta, and that will quickly lead to subclass explosion.

This PR attempts to make that an option. There is a significant constraint in that all Timetable classes must be either plugins or part of Airflow proper, and they have to be serializable.

@collinmcnulty collinmcnulty force-pushed the composable-timetables branch from 31ce9c8 to 1b11250 Compare January 5, 2023 23:07
Comment on lines +28 to +32
def compose_timetable(
run_strategy_cls: type[RunStrategy],
interval_strategy_cls: type[IntervalStrategy],
manual_strategy_cls: type[ManualStrategy],
):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ikind of feel this method is a bit redundant and can simply be implemented with a class…?

@collinmcnulty
Copy link
Contributor Author

The problem is that, for serialization, each timetable has to be a new class, not a new instance of ComposableTimetable. I could make a factory class but that seems even more complex than just having a function.

@uranusjr
Copy link
Member

uranusjr commented Jan 6, 2023

each timetable has to be a new class, not a new instance of ComposableTimetable

Why not? The serialised format can contain instance-level information so the deserialiser can recreate them appropriately.

@collinmcnulty
Copy link
Contributor Author

How would the deserializer have access to the arbitrary subclass for the RunStrategy object to be able to instantiate it? I would love to build it the way you're suggesting, so if there's an answer, I'm all ears.

@uranusjr
Copy link
Member

uranusjr commented Jan 9, 2023

I assume they also need to be registered like timetable classes, since a custom RunStrategy is, similar to timetables, arbitrary code in the scheduler, and we need to safe-guard the invocation.

(With the introduction of RunStrategy classes though, I’m thinking we could probably get rid of timetable registration if a timetable is composed solely from RunStrategy.)

@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Feb 24, 2023
@github-actions github-actions bot closed this Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Stale PRs per the .github/workflows/stale.yml policy file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants