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

Celery task to clear schedule was added #3801

Merged
merged 12 commits into from
Jun 12, 2019
Merged

Conversation

aidarbek
Copy link
Member

@aidarbek aidarbek commented May 14, 2019

What type of PR is this? (check all applicable)

  • Feature

Description

Related Tickets & Documents

Solves #3375 issue

Mobile & Desktop Screenshots/Recordings (if there are UI changes)

Copy link
Contributor

@rauchy rauchy left a comment

Choose a reason for hiding this comment

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

Housekeeping FTW! 🧹

I personally find multiple return values a bit of a code smell here, for two reasons:

  1. High fan-in: while outdated_queries is primarily used in the refresh_queries task, it is called multiple times in tests, so the ordinality becomes baked into several places in code.
  2. Name bias: outdated_queries fetches outdated queries, as in, queries that need to be updated with new values. Housekeeping feels like a side-effect here.

I understand the motivation here is to reuse the database query in Query.outdated_queries, but for code clarity, I would consider splitting this up (if it's not costly, and I tend to believe its not), or finding an elegant solution to the two problems I stated above.

@aidarbek
Copy link
Member Author

aidarbek commented Jun 2, 2019

@rauchy that perfectly makes sense, thanks. I've made some changes, hope everything is good now once all checks are passed

@aidarbek
Copy link
Member Author

aidarbek commented Jun 2, 2019

There are some visual changes that seem unrelated

Copy link
Contributor

@rauchy rauchy left a comment

Choose a reason for hiding this comment

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

Looks better, thanks @aidarbek!

redash/worker.py Outdated
@@ -22,6 +22,10 @@
'task': 'redash.tasks.refresh_queries',
'schedule': timedelta(seconds=30)
},
'empty_schedules': {
'task': 'redash.tasks.empty_schedules',
'schedule': timedelta(seconds=30)
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO this task can run at a much lower frequency. (say, once an hour)

.filter(Query.schedule.isnot(None))
.order_by(Query.id)
)
past_scheduled_queries = []
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it feel like a comprehension or filter would be more apt here? Not sure.

Copy link
Member Author

Choose a reason for hiding this comment

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

Used filter here. Also, added another unit test for this method specifically

@@ -65,3 +67,11 @@ def test_enqueues_parameterized_queries(self):
add_job_mock.assert_called_with(
"select 42", query.data_source, query.user_id,
scheduled_query=query, metadata=ANY)

def test_empty_schedules(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

This guy deserves his own test class too :)

@aidarbek
Copy link
Member Author

aidarbek commented Jun 3, 2019

Some visual changes yet again :)

@gabrieldutra
Copy link
Member

Some visual changes yet again :)

Just sync with master and they'll be gone 🙂

@aidarbek
Copy link
Member Author

aidarbek commented Jun 6, 2019

Hi @rauchy, could you check my latest changes, please?

Copy link
Member

@arikfr arikfr left a comment

Choose a reason for hiding this comment

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

Looks good, @aidarbek ! Thank you for follow ups on the feedback. See two last things in the comments.

def empty_schedules():
queries = models.Query.past_scheduled_queries()
for query in queries:
query.schedule = None
Copy link
Member

Choose a reason for hiding this comment

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

Let's add a log message here, just so admins will be able to traceback changes.

query.latest_query_data = query_result

queries = models.Query.past_scheduled_queries()
self.assertIn(query, queries)
Copy link
Member

Choose a reason for hiding this comment

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

This feels very similar to QueryTest.test_past_scheduled_queries -- why two tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

I just realised that QueryTest would be more appropriate place, but forgot to delete it from here :P

@arikfr arikfr merged commit 2bab144 into getredash:master Jun 12, 2019
@arikfr
Copy link
Member

arikfr commented Jun 12, 2019

Thanks, @aidarbek ! :)

harveyrendell pushed a commit to pushpay/redash that referenced this pull request Nov 14, 2019
* Celery task to clear schedule was added

* fix formating

* empty_schedules task was put in separate task

* worker interval changed, new tests added

* past artifact deleted

* test queries moved to right class, lambda was used to filter data

* unnecessary changes eliminated

* more unnecessary files deleted

* line shortened

* Line shortened more

* codeclimate changes

* Unused test deleted, logs added
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.

4 participants