Skip to content
Snippets Groups Projects
Commit c74cd3aa authored by Sean Arnold's avatar Sean Arnold :speech_balloon: Committed by Stan Hu
Browse files

Update models usage of Time.now => Time.current

- Update specs to match
parent 08ca0a27
No related branches found
No related tags found
No related merge requests found
Showing
with 34 additions and 34 deletions
Loading
Loading
@@ -151,7 +151,7 @@ def defaults
snowplow_app_id: nil,
snowplow_iglu_registry_url: nil,
custom_http_clone_url_root: nil,
productivity_analytics_start_date: Time.now,
productivity_analytics_start_date: Time.current,
snippet_size_limit: 50.megabytes
}
end
Loading
Loading
Loading
Loading
@@ -14,7 +14,7 @@ class BoardGroupRecentVisit < ApplicationRecord
 
def self.visited!(user, board)
visit = find_or_create_by(user: user, group: board.group, board: board)
visit.touch if visit.updated_at < Time.now
visit.touch if visit.updated_at < Time.current
rescue ActiveRecord::RecordNotUnique
retry
end
Loading
Loading
Loading
Loading
@@ -14,7 +14,7 @@ class BoardProjectRecentVisit < ApplicationRecord
 
def self.visited!(user, board)
visit = find_or_create_by(user: user, project: board.project, board: board)
visit.touch if visit.updated_at < Time.now
visit.touch if visit.updated_at < Time.current
rescue ActiveRecord::RecordNotUnique
retry
end
Loading
Loading
Loading
Loading
@@ -137,8 +137,8 @@ def persisted_environment
.includes(:metadata, :job_artifacts_metadata)
end
 
scope :with_artifacts_not_expired, ->() { with_downloadable_artifacts.where('artifacts_expire_at IS NULL OR artifacts_expire_at > ?', Time.now) }
scope :with_expired_artifacts, ->() { with_downloadable_artifacts.where('artifacts_expire_at < ?', Time.now) }
scope :with_artifacts_not_expired, ->() { with_downloadable_artifacts.where('artifacts_expire_at IS NULL OR artifacts_expire_at > ?', Time.current) }
scope :with_expired_artifacts, ->() { with_downloadable_artifacts.where('artifacts_expire_at < ?', Time.current) }
scope :last_month, ->() { where('created_at > ?', Date.today - 1.month) }
scope :manual_actions, ->() { where(when: :manual, status: COMPLETED_STATUSES + %i[manual]) }
scope :scheduled_actions, ->() { where(when: :delayed, status: COMPLETED_STATUSES + %i[scheduled]) }
Loading
Loading
@@ -259,7 +259,7 @@ def retry(build, current_user)
end
 
before_transition any => :waiting_for_resource do |build|
build.waiting_for_resource_at = Time.now
build.waiting_for_resource_at = Time.current
end
 
before_transition on: :enqueue_waiting_for_resource do |build|
Loading
Loading
@@ -713,7 +713,7 @@ def artifacts_paths
end
 
def needs_touch?
Time.now - updated_at > 15.minutes.to_i
Time.current - updated_at > 15.minutes.to_i
end
 
def valid_token?(token)
Loading
Loading
@@ -776,11 +776,11 @@ def erased?
end
 
def artifacts_expired?
artifacts_expire_at && artifacts_expire_at < Time.now
artifacts_expire_at && artifacts_expire_at < Time.current
end
 
def artifacts_expire_in
artifacts_expire_at - Time.now if artifacts_expire_at
artifacts_expire_at - Time.current if artifacts_expire_at
end
 
def artifacts_expire_in=(value)
Loading
Loading
@@ -993,7 +993,7 @@ def erase_trace!
end
 
def update_erased!(user = nil)
self.update(erased_by: user, erased_at: Time.now, artifacts_expire_at: nil)
self.update(erased_by: user, erased_at: Time.current, artifacts_expire_at: nil)
end
 
def unscoped_project
Loading
Loading
@@ -1026,7 +1026,7 @@ def options_retry
end
 
def has_expiring_artifacts?
artifacts_expire_at.present? && artifacts_expire_at > Time.now
artifacts_expire_at.present? && artifacts_expire_at > Time.current
end
 
def job_jwt_variables
Loading
Loading
Loading
Loading
@@ -148,7 +148,7 @@ class JobArtifact < ApplicationRecord
where(file_type: types)
end
 
scope :expired, -> (limit) { where('expire_at < ?', Time.now).limit(limit) }
scope :expired, -> (limit) { where('expire_at < ?', Time.current).limit(limit) }
scope :locked, -> { where(locked: true) }
scope :unlocked, -> { where(locked: [false, nil]) }
 
Loading
Loading
@@ -244,7 +244,7 @@ def hashed_path?
end
 
def expire_in
expire_at - Time.now if expire_at
expire_at - Time.current if expire_at
end
 
def expire_in=(value)
Loading
Loading
Loading
Loading
@@ -163,11 +163,11 @@ class Pipeline < ApplicationRecord
# Create a separate worker for each new operation
 
before_transition [:created, :waiting_for_resource, :preparing, :pending] => :running do |pipeline|
pipeline.started_at = Time.now
pipeline.started_at = Time.current
end
 
before_transition any => [:success, :failed, :canceled] do |pipeline|
pipeline.finished_at = Time.now
pipeline.finished_at = Time.current
pipeline.update_duration
end
 
Loading
Loading
Loading
Loading
@@ -273,7 +273,7 @@ def runner_queue_value_latest?(value)
 
def update_cached_info(values)
values = values&.slice(:version, :revision, :platform, :architecture, :ip_address) || {}
values[:contacted_at] = Time.now
values[:contacted_at] = Time.current
 
cache_attributes(values)
 
Loading
Loading
@@ -309,7 +309,7 @@ def persist_cached_data?
 
real_contacted_at = read_attribute(:contacted_at)
real_contacted_at.nil? ||
(Time.now - real_contacted_at) >= contacted_at_max_age
(Time.current - real_contacted_at) >= contacted_at_max_age
end
 
def tag_constraints
Loading
Loading
Loading
Loading
@@ -37,7 +37,7 @@ class Prometheus < ApplicationRecord
end
 
after_transition any => :updating do |application|
application.update(last_update_started_at: Time.now)
application.update(last_update_started_at: Time.current)
end
end
 
Loading
Loading
Loading
Loading
@@ -136,15 +136,15 @@ class CommitStatus < ApplicationRecord
end
 
before_transition [:created, :waiting_for_resource, :preparing, :skipped, :manual, :scheduled] => :pending do |commit_status|
commit_status.queued_at = Time.now
commit_status.queued_at = Time.current
end
 
before_transition [:created, :preparing, :pending] => :running do |commit_status|
commit_status.started_at = Time.now
commit_status.started_at = Time.current
end
 
before_transition any => [:success, :failed, :canceled] do |commit_status|
commit_status.finished_at = Time.now
commit_status.finished_at = Time.current
end
 
before_transition any => :failed do |commit_status, transition|
Loading
Loading
Loading
Loading
@@ -17,7 +17,7 @@ module EachBatch
# Example:
#
# User.each_batch do |relation|
# relation.update_all(updated_at: Time.now)
# relation.update_all(updated_at: Time.current)
# end
#
# The supplied block is also passed an optional batch index:
Loading
Loading
Loading
Loading
@@ -160,7 +160,7 @@ def calculate_duration
if started_at && finished_at
finished_at - started_at
elsif started_at
Time.now - started_at
Time.current - started_at
end
end
end
Loading
Loading
@@ -24,7 +24,7 @@ def resolvable_types
# The timestamp of the note (e.g. the :created_at or :updated_at attribute if provided via
# API call)
def system_note_timestamp
@system_note_timestamp || Time.now # rubocop:disable Gitlab/ModuleWithInstanceVariables
@system_note_timestamp || Time.current # rubocop:disable Gitlab/ModuleWithInstanceVariables
end
 
attr_writer :system_note_timestamp
Loading
Loading
Loading
Loading
@@ -44,7 +44,7 @@ def calculate_reactive_cache(query_class_name, *args)
{
success: true,
data: data,
last_update: Time.now.utc
last_update: Time.current.utc
}
rescue Gitlab::PrometheusClient::Error => err
{ success: false, result: err.message }
Loading
Loading
Loading
Loading
@@ -23,7 +23,7 @@ module ResolvableNote
class_methods do
# This method must be kept in sync with `#resolve!`
def resolve!(current_user)
unresolved.update_all(resolved_at: Time.now, resolved_by_id: current_user.id)
unresolved.update_all(resolved_at: Time.current, resolved_by_id: current_user.id)
end
 
# This method must be kept in sync with `#unresolve!`
Loading
Loading
@@ -57,7 +57,7 @@ def resolve_without_save(current_user, resolved_by_push: false)
return false unless resolvable?
return false if resolved?
 
self.resolved_at = Time.now
self.resolved_at = Time.current
self.resolved_by = current_user
self.resolved_by_push = resolved_by_push
 
Loading
Loading
Loading
Loading
@@ -64,7 +64,7 @@ class Deployment < ApplicationRecord
end
 
before_transition any => [:success, :failed, :canceled] do |deployment|
deployment.finished_at = Time.now
deployment.finished_at = Time.current
end
 
after_transition any => :success do |deployment|
Loading
Loading
Loading
Loading
@@ -339,7 +339,7 @@ def knative_services_finder
end
 
def auto_stop_in
auto_stop_at - Time.now if auto_stop_at
auto_stop_at - Time.current if auto_stop_at
end
 
def auto_stop_in=(value)
Loading
Loading
Loading
Loading
@@ -11,11 +11,11 @@ class Issue::Metrics < ApplicationRecord
 
def record!
if issue.milestone_id.present? && self.first_associated_with_milestone_at.blank?
self.first_associated_with_milestone_at = Time.now
self.first_associated_with_milestone_at = Time.current
end
 
if issue_assigned_to_list_label? && self.first_added_to_board_at.blank?
self.first_added_to_board_at = Time.now
self.first_added_to_board_at = Time.current
end
 
self.save
Loading
Loading
Loading
Loading
@@ -47,7 +47,7 @@ class JiraImportState < ApplicationRecord
after_transition initial: :scheduled do |state, _|
state.run_after_commit do
job_id = Gitlab::JiraImport::Stage::StartImportWorker.perform_async(project.id)
state.update(jid: job_id, scheduled_at: Time.now) if job_id
state.update(jid: job_id, scheduled_at: Time.current) if job_id
end
end
 
Loading
Loading
Loading
Loading
@@ -39,7 +39,7 @@ def content
end
 
# Populate placeholders in the LicenseTemplate content
def resolve!(project_name: nil, fullname: nil, year: Time.now.year.to_s)
def resolve!(project_name: nil, fullname: nil, year: Time.current.year.to_s)
# Ensure the string isn't shared with any other instance of LicenseTemplate
new_content = content.dup
new_content.gsub!(YEAR_TEMPLATE_REGEX, year) if year.present?
Loading
Loading
Loading
Loading
@@ -320,7 +320,7 @@ def accept_invite!(new_user)
return false unless invite?
 
self.invite_token = nil
self.invite_accepted_at = Time.now.utc
self.invite_accepted_at = Time.current.utc
 
self.user = new_user
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment