Skip to content

Commit

Permalink
Merge pull request #4 from eisuke/time_now
Browse files Browse the repository at this point in the history
s/Time.now/Time.current/
  • Loading branch information
eisuke authored Oct 24, 2016
2 parents 8dc623e + 76d7be7 commit 45d52ba
Show file tree
Hide file tree
Showing 19 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion app/controllers/kuroko2/job_definition_stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def memory
private

def set_period
@end_at = Time.now
@end_at = Time.current

@start_at =
case params[:period]
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/kuroko2/job_timelines_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def find_user
end

def set_period
@end_at = Time.now
@end_at = Time.current

@start_at =
case params[:period]
Expand Down
4 changes: 2 additions & 2 deletions app/models/kuroko2/execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ def self.poll(queue = DEFAULT_QUEUE)
end

def finish(output:, exit_status:)
update!(output: output, exit_status: exit_status, finished_at: Time.now)
update!(output: output, exit_status: exit_status, finished_at: Time.current)
job_definition.memory_expectancy.calculate!
end

def finish_by_signal(output:, term_signal:)
update!(output: output, term_signal: term_signal, finished_at: Time.now)
update!(output: output, term_signal: term_signal, finished_at: Time.current)
job_definition.memory_expectancy.calculate!
end

Expand Down
4 changes: 2 additions & 2 deletions app/models/kuroko2/job_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def log_memory_consumption(value)
end

def execution_minutes
(((error_at || canceled_at || finished_at || Time.now) - created_at).to_f / 60).round(2)
(((error_at || canceled_at || finished_at || Time.current) - created_at).to_f / 60).round(2)
end

def status
Expand Down Expand Up @@ -98,7 +98,7 @@ def generate_token
token.script = self.script
token.context = {
meta: {
launched_time: Time.now,
launched_time: Time.current,
job_definition_id: definition.id,
job_definition_name: definition.name,
job_instance_id: id,
Expand Down
2 changes: 1 addition & 1 deletion app/models/kuroko2/job_schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Kuroko2::JobSchedule < Kuroko2::ApplicationRecord
validates :cron, format: { with: CRON_FORMAT }, uniqueness: { scope: :job_definition_id }
validate :validate_cron_schedule

def next(now = Time.now)
def next(now = Time.current)
if 1.month.ago(now).future?
Kuroko2.logger.warn("Exceeds the time of criteria #{now}. (Up to 1 month since)")
return
Expand Down
4 changes: 2 additions & 2 deletions lib/kuroko2/command/monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ def check_process_absence(execution)

def log_memory_consumption?(execution)
if @intervals[execution.id]
@intervals[execution.id].reached?(Time.now)
@intervals[execution.id].reached?(Time.current)
else # first time
@intervals[execution.id] = MemoryConsumptionLog::Interval.new(Time.now)
@intervals[execution.id] = MemoryConsumptionLog::Interval.new(Time.current)
true
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/kuroko2/execution_logger/cloud_watch_logs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_logs(token = @get_log_token)
private

def timestamp_now
(Time.now.to_f * 1000).to_i # milliseconds
(Time.current.to_f * 1000).to_i # milliseconds
end

def create_log_stream
Expand Down
2 changes: 1 addition & 1 deletion lib/kuroko2/workflow/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def run
begin
@processing.set!
JobSchedule.transaction do
now = Time.now
now = Time.current
last_scheduled_time = Tick.fetch_then_update(now)
JobSchedule.launch_scheduled_jobs!(last_scheduled_time, now)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/kuroko2/workflow/task/execute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def update_execution(execution)
def process_timeout_if_needed(execution)
timeout = token.context['TIMEOUT'].to_i

if timeout > 0 && ((execution.created_at + timeout.minutes) < Time.now) && execution.pid
if timeout > 0 && ((execution.created_at + timeout.minutes) < Time.current) && execution.pid
hostname = Worker.executing(execution.id).try(:hostname)
if hostname
ProcessSignal.create!(pid: execution.pid, hostname: hostname)
Expand Down Expand Up @@ -114,7 +114,7 @@ def elapsed_expected_time?(execution)

def notify_long_elapsed_time_if_needed(execution)
if available_notify_long_elapsed_time?(execution) && elapsed_expected_time?(execution)
token.context['EXPECTED_TIME_NOTIFIED_AT'] = Time.now
token.context['EXPECTED_TIME_NOTIFIED_AT'] = Time.current
Notifier.notify(:long_elapsed_time, token.job_instance)

message = "(token #{token.uuid}) The running time is longer than #{expected_time} minutes!"
Expand Down
4 changes: 2 additions & 2 deletions lib/kuroko2/workflow/task/sleep.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ module Task
class Sleep < Base
def execute
if (time = token.context['SLEEP'])
if Time.now.to_i > time
if Time.current.to_i > time
token.context.delete('SLEEP')

:next
else
:pass
end
else
token.context['SLEEP'] = Time.now.to_i + option.to_i
token.context['SLEEP'] = Time.current.to_i + option.to_i

:pass
end
Expand Down
4 changes: 2 additions & 2 deletions lib/kuroko2/workflow/task/wait.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def validate
private

# ex. wait: 100/daily 200/daily
def parse_option(option, start_at: Time.now)
def parse_option(option, start_at: Time.current)
raise_assertion_error unless option

wait_option = { "jobs" => [], "timeout" => 60.minutes.to_i / 1.minute }
Expand Down Expand Up @@ -113,7 +113,7 @@ def receive_waiting_job_completion!
end
end

def period_to_time(period, at: Time.now)
def period_to_time(period, at: Time.current)
case period
when "hourly"
[at.beginning_of_hour, at.end_of_hour]
Expand Down
4 changes: 2 additions & 2 deletions spec/command/monitor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Kuroko2::Command
let(:sent_mail) { ActionMailer::Base.deliveries.last }

context 'not running process' do
let!(:execution) { create(:execution, token: token, worker: worker, started_at: Time.now, finished_at: nil, pid: pid) }
let!(:execution) { create(:execution, token: token, worker: worker, started_at: Time.current, finished_at: nil, pid: pid) }
let(:monitor) { Kuroko2::Command::Monitor.new(hostname: hostname, worker_id: 1) }

subject! { 15.times { monitor.execute } }
Expand Down Expand Up @@ -44,7 +44,7 @@ module Kuroko2::Command
end

describe 'memory consumption monitoring' do
let!(:execution) { create(:execution, token: token, worker: worker, started_at: Time.now, finished_at: nil, pid: pid) }
let!(:execution) { create(:execution, token: token, worker: worker, started_at: Time.current, finished_at: nil, pid: pid) }
let(:monitor) { Kuroko2::Command::Monitor.new(hostname: hostname, worker_id: 1) }
before do
allow(monitor).to receive(:check_process_absence).and_return(true)
Expand Down
2 changes: 1 addition & 1 deletion spec/execution_logger/cloud_watch_logs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
end

describe '#put_logs' do
let(:events) { [{ timestamp: Time.now.to_i * 1000, message: 'hello' }] }
let(:events) { [{ timestamp: Time.current.to_i * 1000, message: 'hello' }] }
let(:response) { double('Response', data: { next_sequence_token: 'abc' })}

let(:send_parameters) do
Expand Down
4 changes: 2 additions & 2 deletions spec/factories/execution_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
job_instance { token.job_instance if token }
context { token.context if token }

started_at { Time.now }
finished_at { Time.now }
started_at { Time.current }
finished_at { Time.current }
end
end
6 changes: 3 additions & 3 deletions spec/models/job_instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,23 @@
let(:definition) { create(:job_definition) }

context 'with finished_at present' do
let(:finished_at) { Time.now }
let(:finished_at) { Time.current }

it 'returns "success"' do
expect(instance.status).to eq('success')
end
end

context 'with canceled_at present' do
let(:canceled_at) { Time.now }
let(:canceled_at) { Time.current }

it 'returns "canceled"' do
expect(instance.status).to eq('canceled')
end
end

context 'with error_at present' do
let(:error_at) { Time.now }
let(:error_at) { Time.current }

it 'returns "error"' do
expect(instance.status).to eq('error')
Expand Down
8 changes: 4 additions & 4 deletions spec/models/memory_consumption_log_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
require 'rails_helper'

RSpec.describe Kuroko2::MemoryConsumptionLog do
around {|example| Timecop.freeze(Time.now) { example.run } }
around {|example| Timecop.freeze(Time.current) { example.run } }

describe described_class::Interval do
describe '#reached?' do
let(:interval) { described_class.new(base, count) }
let(:base) { Time.now }
let(:base) { Time.current }

context 'count = 0 and 2 seconds since' do
let(:count) { 0 }
Expand All @@ -29,7 +29,7 @@

describe '#next' do
it 'returns count-up-ed Interval' do
a = described_class.new(Time.now)
a = described_class.new(Time.current)
b = a.next
expect(b).to be_a(described_class)

Expand All @@ -39,7 +39,7 @@
end

it 'behaves as certain period interval with #reached? and #next' do
a = described_class.new(Time.now, 100)
a = described_class.new(Time.current, 100)
expect(a.reached?(29.minutes.since.to_time)).to be_falsy
expect(a.reached?(31.minutes.since.to_time)).to be_truthy
b = a.next
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/api/job_instances_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
end

context 'with job_instance succeeded' do
let(:instance) { create(:job_instance, job_definition: definition, finished_at: Time.now, error_at: nil, canceled_at: nil) }
let(:instance) { create(:job_instance, job_definition: definition, finished_at: Time.current, error_at: nil, canceled_at: nil) }

it 'returns "success" as status' do
get "/v1/definitions/#{definition.id}/instances/#{instance.id}", params: {}, env: env
Expand Down
2 changes: 1 addition & 1 deletion spec/workflow/task/execute_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ module Kuroko2::Workflow::Task
end

context 'When EXPECTED_TIME_NOTIFIED_AT is now' do
let(:notified_time) { Time.now }
let(:notified_time) { Time.current }

it 'does not alert warnings' do
expect(Kuroko2::Workflow::Notifier).not_to receive(:notify)
Expand Down
4 changes: 2 additions & 2 deletions spec/workflow/task/wait_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Kuroko2::Workflow::Task
context 'with valid syntax' do
let(:definition) { create(:job_definition, script: "wait: #{option}") }
let(:instance) do
create(:job_instance, job_definition: definition, created_at: Time.now).tap do |instance|
create(:job_instance, job_definition: definition, created_at: Time.current).tap do |instance|
instance.tokens.destroy
end
end
Expand Down Expand Up @@ -123,7 +123,7 @@ module Kuroko2::Workflow::Task
end

context 'with invalid syntax' do
let(:token) { build(:token, job_instance: build(:job_instance, created_at: Time.now)) }
let(:token) { build(:token, job_instance: build(:job_instance, created_at: Time.current)) }

context 'with invalid job_definition_id' do
let(:option) { 'AAA/daily' }
Expand Down

0 comments on commit 45d52ba

Please sign in to comment.