Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lost runs in CronTriggerTimetable #32921

Conversation

BohdanSemonov
Copy link

@BohdanSemonov BohdanSemonov commented Jul 28, 2023

closes: #27399

Fix lost runs in CronTriggerTimetable by resetting seconds and microseconds in start_time_candidates.


^ Add meaningful description above

Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

@boring-cyborg
Copy link

boring-cyborg bot commented Jul 28, 2023

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: [email protected]
    Slack: https://s.apache.org/airflow-slack

@BohdanSemonov BohdanSemonov changed the title Add resetting seconds and microseconds that fixes losing runs by Cron… Add resetting of seconds and microseconds that fixes losing runs by Cron Jul 28, 2023
@BohdanSemonov BohdanSemonov changed the title Add resetting of seconds and microseconds that fixes losing runs by Cron Add resetting of seconds and microseconds that fixes losing runs by CronTriggerTimetable Jul 28, 2023
@BohdanSemonov BohdanSemonov changed the title Add resetting of seconds and microseconds that fixes losing runs by CronTriggerTimetable Add resetting of seconds and microseconds that fixes runs losing by CronTriggerTimetable Jul 28, 2023
@@ -89,7 +89,7 @@ def next_dagrun_info(
else:
next_start_time = self._align_to_next(restriction.earliest)
else:
start_time_candidates = [self._align_to_next(DateTime.utcnow())]
start_time_candidates = [self._align_to_next(DateTime.utcnow().replace(second=0, microsecond=0))]
Copy link
Member

Choose a reason for hiding this comment

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

This makes sense 🤔

Could you add a test for this change? (a test which fails without resetting seconds and microsecond and passes after applying your change)

Copy link
Member

Choose a reason for hiding this comment

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

Nice one, yeah. That would definitely explain occasionally lost dag runs

Copy link
Member

Choose a reason for hiding this comment

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

And yeah - having a test for that would be fantastic - if you need help @BohdanSemonov - we can suggest an approach here.

Copy link
Member

@uranusjr uranusjr Jul 31, 2023

Choose a reason for hiding this comment

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

Wouldn’t this still have problems if the scheduler is a tad too slow and fails to schedule the DAG in a minute? I still prefer the _align_to_prev fix over this.

Copy link
Member

Choose a reason for hiding this comment

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

@uranusjr - could you please elaborate? Is there a fix in progress you are referring to? Or some new code to be written? It wasn't too clear. I think it would be worth to consider fixing this problem for 2.7.0

Copy link
Member

Choose a reason for hiding this comment

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

The linked issue already contains discussion before this fix was proposed.

Copy link
Member

@potiuk potiuk Aug 7, 2023

Choose a reason for hiding this comment

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

Yeah. There are 3 linked issues and each of them has tens of comments. Maybe that is obvious to you, but would be great to point to it. A link to specific comment would be great, otherwise it forces somoene looking here to read the entire conversation (and few of those) to find it..

Copy link
Member

Choose a reason for hiding this comment

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

(Just try to see the other side of people who are participating in multiple discussions and might not remember all of it).

Choose a reason for hiding this comment

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

I believe he means the change shown in these 2 comments. Apologies for interjecting, but I am excited for this fix so wanted to help keep things moving.

#27399 (comment)
#27399 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

I think it relies on @uranusjr -> I am unable to assess if it's good enough or not at this stage and how to move forward.

@hussein-awala hussein-awala changed the title Add resetting of seconds and microseconds that fixes runs losing by CronTriggerTimetable Fix lost runs in CronTriggerTimetable by resetting seconds and microseconds in start_time_candidates Jul 29, 2023
@hussein-awala hussein-awala changed the title Fix lost runs in CronTriggerTimetable by resetting seconds and microseconds in start_time_candidates Fix lost runs in CronTriggerTimetable Jul 29, 2023
@potiuk
Copy link
Member

potiuk commented Jul 30, 2023

I think it also fixes #31687 which is essentially a duplicate of #27399.

@uranusjr WDYT?

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.6.1 Queued DagRun for some DAGs, and for some not CronTriggerTimetable lost one task occasionally
6 participants