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

Rails/TimeZone-20230531233329 #213

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config --exclude-limit 180`
# on 2023-04-20 23:33:11 UTC using RuboCop version 1.50.2.
# on 2023-05-31 23:33:50 UTC using RuboCop version 1.51.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -377,18 +377,6 @@ Rails/SkipsModelValidations:
- 'spec/lib/dispatch-rider/queue_services/file_system_spec.rb'
- 'spec/lib/dispatch-rider/queue_services/simple_spec.rb'

# Offense count: 10
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: strict, flexible
Rails/TimeZone:
Exclude:
- 'lib/dispatch-rider/logging/lifecycle_logger.rb'
- 'lib/dispatch-rider/queue_services/aws_sqs.rb'
- 'lib/dispatch-rider/queue_services/aws_sqs/sqs_received_message.rb'
- 'lib/dispatch-rider/scheduled_job.rb'
- 'spec/lib/dispatch-rider/queue_services/aws_sqs_spec.rb'

# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
Security/JSONLoad:
Expand Down
4 changes: 2 additions & 2 deletions lib/dispatch-rider/logging/lifecycle_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ def log_got_stop(reason, message)
end

def wrap_handling(message)
start_time = Time.now
start_time = Time.zone.now
log_start(message)
yield
log_success(message)
rescue => exception
log_fail(message, exception)
raise exception
ensure
log_complete(message, Time.now - start_time)
log_complete(message, Time.zone.now - start_time)
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/dispatch-rider/queue_services/aws_sqs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def set_visibility_timeout(client, url)
def visibility_timeout_shield(message)
yield
ensure
duration = Time.now - message.start_time
duration = Time.zone.now - message.start_time
timeout = message.total_timeout
if duration > timeout
message = "message: #{message.subject}, #{message.body.inspect} took #{duration} seconds while the timeout was #{timeout}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class SqsReceivedMessage < ReceivedMessage
def initialize(message, raw_item, queue, queue_visibility_timeout)
@queue = queue
@total_timeout = queue_visibility_timeout.to_i
@start_time = Time.now
@start_time = Time.zone.now
super(message, raw_item)
end

Expand All @@ -19,7 +19,7 @@ def extend_timeout(timeout)
item.change_visibility({
visibility_timeout: timeout # required
})
@total_timeout = timeout + (Time.now - start_time).to_i if timeout > 0
@total_timeout = timeout + (Time.zone.now - start_time).to_i if timeout > 0
end

# We effectively return the item to the queue by setting
Expand Down
6 changes: 3 additions & 3 deletions lib/dispatch-rider/scheduled_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def get_new_claim_stub
:message,
presence: true

scope :due, -> (time = Time.now) { where "scheduled_at <= ?", time }
scope :claimed_by, -> (claim_id) { where(claim_id: claim_id).where "claim_expires_at > ?", Time.now }
scope :unclaimed, -> { where "claim_expires_at IS NULL OR claim_expires_at <= ?", Time.now }
scope :due, -> (time = Time.zone.now) { where "scheduled_at <= ?", time }
scope :claimed_by, -> (claim_id) { where(claim_id: claim_id).where "claim_expires_at > ?", Time.zone.now }
scope :unclaimed, -> { where "claim_expires_at IS NULL OR claim_expires_at <= ?", Time.zone.now }

def publish
publisher.publish(destinations: destinations, message: message)
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/dispatch-rider/queue_services/aws_sqs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"SenderId" => "123456789012",
"SentTimestamp" => Time.now.to_i.to_s,
"ApproximateReceivedCount" => "12",
"ApproximateFirstReceiveTimestamp" => (Time.now + 12).to_i.to_s,
"ApproximateFirstReceiveTimestamp" => (Time.zone.now + 12).to_i.to_s,
}
end

Expand Down Expand Up @@ -124,7 +124,7 @@
"SenderId" => "123456789012",
"SentTimestamp" => Time.now.to_i.to_s,
"ApproximateReceivedCount" => "12",
"ApproximateFirstReceiveTimestamp" => (Time.now + 12).to_i.to_s,
"ApproximateFirstReceiveTimestamp" => (Time.zone.now + 12).to_i.to_s,
}
end

Expand Down