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 dashboard jobs endless pagination with timezone handling #251

Merged
merged 1 commit into from
May 17, 2021

Conversation

morgoth
Copy link
Collaborator

@morgoth morgoth commented May 14, 2021

Having config.time_zone = "Europe/Berlin" in the app, to properly handle time zone, we need to parse timestamp.
The difference before the patch:

irb(main):033:0> GoodJob::Job.display_all(after_scheduled_at: '2021-04-21 10:36:12 +0200').count
   (1.3ms)  SELECT COUNT(*) FROM "good_jobs" WHERE ((COALESCE(scheduled_at, created_at)) < ('2021-04-21 10:36:12 +0200'))
=> 1
irb(main):034:0> GoodJob::Job.display_all(after_scheduled_at: Time.zone.parse('2021-04-21 10:36:12 +0200')).count
   (1.2ms)  SELECT COUNT(*) FROM "good_jobs" WHERE ((COALESCE(scheduled_at, created_at)) < ('2021-04-21 08:36:12'))
=> 0

Copy link
Owner

@bensheldon bensheldon left a comment

Choose a reason for hiding this comment

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

@morgoth I'm so glad you caught this! I requested a change about where the type coercion happens. Let me know if you have thoughts about that.

@@ -126,6 +126,8 @@ def self.queue_parser(string)
# @return [ActiveRecord::Relation]
scope :display_all, (lambda do |after_scheduled_at: nil, after_id: nil|
query = order(Arel.sql('COALESCE(scheduled_at, created_at) DESC, id DESC'))
after_scheduled_at = Time.zone.parse(after_scheduled_at) if after_scheduled_at.present?
Copy link
Owner

Choose a reason for hiding this comment

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

This will fail if after_scheduled_at is a Time or DateTime. My preference would be that type coercion happens in the controller (close to where it's coming in as a string), and models operate off of higher level objects (like Time/DateTime) rather than primitives (like Strings)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

@bensheldon
Copy link
Owner

@morgoth Also, I apologize that there are some flakes in the Java Test Suite right now. I'm just re-running checks if they have an isolated failure and hopefully building up an understanding of where the flake is.

Having `config.time_zone = "Europe/Berlin"` in the app, to properly handle time zone, we need to parse timestamp.
The difference before the patch:

```
irb(main):033:0> GoodJob::Job.display_all(after_scheduled_at: '2021-04-21 10:36:12 +0200').count
   (1.3ms)  SELECT COUNT(*) FROM "good_jobs" WHERE ((COALESCE(scheduled_at, created_at)) < ('2021-04-21 10:36:12 +0200'))
=> 1
irb(main):034:0> GoodJob::Job.display_all(after_scheduled_at: Time.zone.parse('2021-04-21 10:36:12 +0200')).count
   (1.2ms)  SELECT COUNT(*) FROM "good_jobs" WHERE ((COALESCE(scheduled_at, created_at)) < ('2021-04-21 08:36:12'))
=> 0
```
@bensheldon bensheldon added the bug Something isn't working label May 17, 2021
@bensheldon bensheldon changed the title Fixed jobs endless pagination. Fix dashboard jobs endless pagination with timezone handling May 17, 2021
@bensheldon bensheldon merged commit b144a49 into bensheldon:main May 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants