You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/04/12 20:45:51 UTC
[GitHub] [airflow] BasPH opened a new pull request #8266: Fix non updating
DAG code by checking against last modification time
BasPH opened a new pull request #8266: Fix non updating DAG code by checking against last modification time
URL: https://github.com/apache/airflow/pull/8266
The DAG code only seemed to update in certain conditions. After closer inspection, it turns out we save utcnow() in the last_updated column. With a threshold of 120 seconds, the result was that a file updated within two minutes from the last utcnow(), will never be updated.
This change simply checks if the last updated time is larger than the last updated time registered in the DB. If so, that means a change and the file is updated.
Draft for now, because I don't understand the reasoning for a 120 second threshold yet, plus want to check tests. @kaxil why was the 120 second threshold in there? Simply checking for a different modification time makes more sense to me, with this change I instantly see the updated code in the webserver, and I don't think people update DAG code every second.
Lastly, I noticed the other views seem to suffer from a similar bug when using `AIRFLOW__CORE__STORE_SERIALIZED_DAGS=True`. Clicking Refresh in the UI doesn't update the DAG structure if I add a new task. Will cover in a separate issue.
---
Make sure to mark the boxes below before creating PR: [x]
- [ ] Description above provides context of the change
- [ ] Unit tests coverage for changes (not needed for documentation changes)
- [ ] Commits follow "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)"
- [ ] Relevant documentation is updated including usage instructions.
- [ ] I will engage committers as explained in [Contribution Workflow Example](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#contribution-workflow-example).
---
In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in [UPDATING.md](https://github.com/apache/airflow/blob/master/UPDATING.md).
Read the [Pull Request Guidelines](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#pull-request-guidelines) for more information.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [airflow] BasPH commented on issue #8266: Fix non updating DAG code
by checking against last modification time
Posted by GitBox <gi...@apache.org>.
BasPH commented on issue #8266: Fix non updating DAG code by checking against last modification time
URL: https://github.com/apache/airflow/pull/8266#issuecomment-612859408
Done. If there is a strong reason to only write after a certain interval, we can make it configurable, but for now I changed to code to write DagCode any time a change is detected.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [airflow] kaxil commented on a change in pull request #8266: Fix
non updating DAG code by checking against last modification time
Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #8266: Fix non updating DAG code by checking against last modification time
URL: https://github.com/apache/airflow/pull/8266#discussion_r407435121
##########
File path: airflow/models/dagcode.py
##########
@@ -124,15 +124,14 @@ def bulk_sync_to_db(cls, filelocs: Iterable[str], session=None):
session.add(orm_dag_code)
for fileloc in existing_filelocs:
- old_version = existing_orm_dag_codes_by_fileloc_hashes[
- filelocs_to_hashes[fileloc]
- ]
- file_modified = datetime.fromtimestamp(
- os.path.getmtime(correct_maybe_zipped(fileloc)), tz=timezone.utc)
+ current_version = existing_orm_dag_codes_by_fileloc_hashes[filelocs_to_hashes[fileloc]]
+ file_mod_time = datetime.fromtimestamp(
+ os.path.getmtime(correct_maybe_zipped(fileloc)), tz=timezone.utc
+ )
- if (file_modified - timedelta(seconds=120)) > old_version.last_updated:
Review comment:
You will have to remove `timedelta` from the import statement at the top of the file. Pylint was failing with "import not used"
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [airflow] BasPH edited a comment on issue #8266: Fix non updating
DAG code by checking against last modification time
Posted by GitBox <gi...@apache.org>.
BasPH edited a comment on issue #8266: Fix non updating DAG code by checking against last modification time
URL: https://github.com/apache/airflow/pull/8266#issuecomment-612806547
> The reason we might want to make this number configurable is so that we don't write to the table more often than needed.
From a user-experience point of view I'd default this to zero, or completely remove the interval.
The scheduler already loops over all files all the time, making many DB calls. Is a user-effected change causing one single DB call using an existing DB session really making any difference?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [airflow] kaxil commented on issue #8266: Fix non updating DAG code
by checking against last modification time
Posted by GitBox <gi...@apache.org>.
kaxil commented on issue #8266: Fix non updating DAG code by checking against last modification time
URL: https://github.com/apache/airflow/pull/8266#issuecomment-612674921
Re: AIRFLOW__CORE__STORE_SERIALIZED_DAGS=True
We have https://airflow.apache.org/docs/stable/configurations-ref.html#min-serialized-dag-update-interval (`min_serialized_dag_update_interval`), you can decrease this number if your DAGs are updated frequently.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [airflow] kaxil commented on issue #8266: Fix non updating DAG code
by checking against last modification time
Posted by GitBox <gi...@apache.org>.
kaxil commented on issue #8266: Fix non updating DAG code by checking against last modification time
URL: https://github.com/apache/airflow/pull/8266#issuecomment-612857738
Yeah, I agree. Can you fix the static test please?
cc @anitakar Was there a reason for a 120s threshold? Just want to make sure I am not missing something. Original PR: https://github.com/apache/airflow/pull/7217
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [airflow] kaxil merged pull request #8266: Fix non updating DAG
code by checking against last modification time
Posted by GitBox <gi...@apache.org>.
kaxil merged pull request #8266: Fix non updating DAG code by checking against last modification time
URL: https://github.com/apache/airflow/pull/8266
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [airflow] kaxil commented on issue #8266: Fix non updating DAG code
by checking against last modification time
Posted by GitBox <gi...@apache.org>.
kaxil commented on issue #8266: Fix non updating DAG code by checking against last modification time
URL: https://github.com/apache/airflow/pull/8266#issuecomment-612674645
Can you also update the test mentioned in https://github.com/apache/airflow/issues/8249#issuecomment-612642283
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [airflow] BasPH commented on issue #8266: Fix non updating DAG code
by checking against last modification time
Posted by GitBox <gi...@apache.org>.
BasPH commented on issue #8266: Fix non updating DAG code by checking against last modification time
URL: https://github.com/apache/airflow/pull/8266#issuecomment-612673832
Related bug: https://github.com/apache/airflow/issues/8249
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [airflow] BasPH commented on issue #8266: Fix non updating DAG code
by checking against last modification time
Posted by GitBox <gi...@apache.org>.
BasPH commented on issue #8266: Fix non updating DAG code by checking against last modification time
URL: https://github.com/apache/airflow/pull/8266#issuecomment-612806547
> The reason we might want to make this number configurable is so that we don't write to the table more often than needed.
From a user-experience point of view I'd default this to zero, or completely remove it.
The scheduler already loops over all files all the time, making many DB calls. Is a user-effected change causing one single DB call using an existing DB session really making any difference?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [airflow] BasPH edited a comment on issue #8266: Fix non updating
DAG code by checking against last modification time
Posted by GitBox <gi...@apache.org>.
BasPH edited a comment on issue #8266: Fix non updating DAG code by checking against last modification time
URL: https://github.com/apache/airflow/pull/8266#issuecomment-612859408
Done. If there is a strong reason to only write after a certain interval, we can make it configurable, but for now I changed the code to write DagCode any time a change is detected.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [airflow] BasPH commented on a change in pull request #8266: Fix
non updating DAG code by checking against last modification time
Posted by GitBox <gi...@apache.org>.
BasPH commented on a change in pull request #8266: Fix non updating DAG code by checking against last modification time
URL: https://github.com/apache/airflow/pull/8266#discussion_r407435793
##########
File path: airflow/models/dagcode.py
##########
@@ -124,15 +124,14 @@ def bulk_sync_to_db(cls, filelocs: Iterable[str], session=None):
session.add(orm_dag_code)
for fileloc in existing_filelocs:
- old_version = existing_orm_dag_codes_by_fileloc_hashes[
- filelocs_to_hashes[fileloc]
- ]
- file_modified = datetime.fromtimestamp(
- os.path.getmtime(correct_maybe_zipped(fileloc)), tz=timezone.utc)
+ current_version = existing_orm_dag_codes_by_fileloc_hashes[filelocs_to_hashes[fileloc]]
+ file_mod_time = datetime.fromtimestamp(
+ os.path.getmtime(correct_maybe_zipped(fileloc)), tz=timezone.utc
+ )
- if (file_modified - timedelta(seconds=120)) > old_version.last_updated:
Review comment:
Whoops, fixed
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services