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

Use global log method #885

Merged
merged 2 commits into from
Dec 13, 2016
Merged
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
6 changes: 3 additions & 3 deletions app/models/changeset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def cycle_issues(issues_changeset_is_resolving, new_issues_created_by_changeset,
.each(&:deprecate)
else
message = unresolved_issues.map { |issue| "Issue #{issue.id} was not resolved." }.join(" ")
logger.error "Error applying Changeset #{self.id}: #{message}"
log "Error applying Changeset #{self.id}: #{message}", :error
raise Changeset::Error.new(changeset: self, message: message)
end
end
Expand Down Expand Up @@ -290,8 +290,8 @@ def apply!
cycle_issues(issues_changeset_is_resolving, new_issues_created_by_changeset, old_issues_to_deprecate)

rescue StandardError => error
logger.error "Error applying Changeset #{self.id}: #{error.message}"
logger.error error.backtrace
log "Error applying Changeset #{self.id}: #{error.message}", :error
log error.backtrace, :error
raise Changeset::Error.new(changeset: self, message: error.message, backtrace: error.backtrace)
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/workers/changeset_apply_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ChangesetApplyWorker
retry: false

def perform(changeset_id, cachekey)
logger.info "ChangesetApplyWorker: #{changeset_id}"
log "ChangesetApplyWorker: #{changeset_id}"
# Processing
errors = []
warnings = []
Expand Down
2 changes: 1 addition & 1 deletion app/workers/feed_activation_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class FeedActivationWorker
include Sidekiq::Worker

def perform(feed_onestop_id, feed_version_sha1, import_level)
logger.info "FeedActivationWorker #{feed_onestop_id}: activating #{feed_version_sha1} at import_level #{import_level}"
log "FeedActivationWorker #{feed_onestop_id}: activating #{feed_version_sha1} at import_level #{import_level}"
# Find Feed & FeedVersions
feed = Feed.find_by_onestop_id!(feed_onestop_id)
new_active_feed_version = feed.feed_versions.find_by!(sha1: feed_version_sha1)
Expand Down
2 changes: 1 addition & 1 deletion app/workers/feed_deactivation_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class FeedDeactivationWorker
include Sidekiq::Worker

def perform(feed_onestop_id, feed_version_sha1)
logger.info "FeedDeactivationWorker #{feed_onestop_id}: deactivating #{feed_version_sha1}"
log "FeedDeactivationWorker #{feed_onestop_id}: deactivating #{feed_version_sha1}"
# Find Feed & FeedVersions
feed = Feed.find_by_onestop_id!(feed_onestop_id)
old_active_feed_version = feed.feed_versions.find_by!(sha1: feed_version_sha1)
Expand Down
10 changes: 5 additions & 5 deletions app/workers/feed_eater_schedule_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class FeedEaterScheduleWorker
sidekiq_options queue: :feed_eater_schedule, retry: false

def perform(feed_onestop_id, feed_version_sha1, feed_schedule_import_id, trip_ids, agency_map, route_map, stop_map, rsp_map)
logger.info "FeedEaterScheduleWorker #{feed_onestop_id}: Importing #{trip_ids.size} trips"
log "FeedEaterScheduleWorker #{feed_onestop_id}: Importing #{trip_ids.size} trips"
feed = Feed.find_by(onestop_id: feed_onestop_id)
feed_version = FeedVersion.find_by(sha1: feed_version_sha1)
feed_schedule_import = FeedScheduleImport.find(feed_schedule_import_id)
Expand All @@ -21,14 +21,14 @@ def perform(feed_onestop_id, feed_version_sha1, feed_schedule_import_id, trip_id
)
rescue Exception => e
exception_log = "\n#{e}\n#{e.backtrace}\n"
logger.error exception_log
log exception_log, :error
feed_schedule_import.failed(exception_log: exception_log)
Raven.capture_exception(e) if defined?(Raven)
else
logger.info "FeedEaterScheduleWorker #{feed_onestop_id}: Saving successful schedule import"
log "FeedEaterScheduleWorker #{feed_onestop_id}: Saving successful schedule import"
feed_schedule_import.succeeded
if feed_schedule_import.all_succeeded?
logger.info "FeedEaterScheduleWorker #{feed_onestop_id}: Enqueing FeedActivationWorker: #{feed.onestop_id} #{feed_version.sha1}, import_level #{import_level}"
log "FeedEaterScheduleWorker #{feed_onestop_id}: Enqueing FeedActivationWorker: #{feed.onestop_id} #{feed_version.sha1}, import_level #{import_level}"
FeedActivationWorker.perform_async(
feed.onestop_id,
feed_version.sha1,
Expand All @@ -37,7 +37,7 @@ def perform(feed_onestop_id, feed_version_sha1, feed_schedule_import_id, trip_id
end
ensure
feed_version.file.remove_any_local_cached_copies
logger.info "FeedEaterScheduleWorker #{feed_onestop_id}: Saving log"
log "FeedEaterScheduleWorker #{feed_onestop_id}: Saving log"
feed_schedule_import.update(import_log: graph.try(:import_log))
end
end
Expand Down
12 changes: 6 additions & 6 deletions app/workers/feed_eater_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def perform(feed_onestop_id, feed_version_sha1=nil, import_level=0)
# Import feed
graph = nil
begin
logger.info "FeedEaterWorker #{feed_onestop_id}: Importing feed at import level #{import_level}"
log "FeedEaterWorker #{feed_onestop_id}: Importing feed at import level #{import_level}"
graph = GTFSGraph.new(feed, feed_version)
graph.cleanup
graph.create_change_osr
Expand All @@ -37,28 +37,28 @@ def perform(feed_onestop_id, feed_version_sha1=nil, import_level=0)
schedule_jobs << [feed_schedule_import.id, trip_ids, agency_map, route_map, stop_map, rsp_map]
end
schedule_jobs.each do |feed_schedule_import_id, trip_ids, agency_map, route_map, stop_map, rsp_map|
logger.info "FeedEaterWorker #{feed_onestop_id}: Enqueue schedule job"
log "FeedEaterWorker #{feed_onestop_id}: Enqueue schedule job"
FeedEaterScheduleWorker.perform_async(feed.onestop_id, feed_version.sha1, feed_schedule_import_id, trip_ids, agency_map, route_map, stop_map, rsp_map)
end
end
rescue Exception => e
# NOTE: we're catching all exceptions, including Interrupt,
# SignalException, and SyntaxError
exception_log = "\n#{e}\n#{e.backtrace}\n"
logger.error exception_log
logger.info "FeedEaterWorker #{feed_onestop_id}: Saving failed feed import"
log exception_log, :error
log "FeedEaterWorker #{feed_onestop_id}: Saving failed feed import"
feed_version_import.failed(exception_log: exception_log)
Raven.capture_exception(e) if defined?(Raven)
else
# Enqueue FeedEaterScheduleWorker jobs, or save successful import.
if import_level < 2
logger.info "FeedEaterWorker #{feed_onestop_id}: Saving successful feed import"
log "FeedEaterWorker #{feed_onestop_id}: Saving successful feed import"
feed_version_import.succeeded
end
ensure
feed_version.file.remove_any_local_cached_copies
# Save logs and reports
logger.info "FeedEaterWorker #{feed_onestop_id}: Saving log"
log "FeedEaterWorker #{feed_onestop_id}: Saving log"
feed_version_import.update(import_log: graph.try(:import_log))
end
end
Expand Down
10 changes: 5 additions & 5 deletions app/workers/feed_fetcher_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ class FeedFetcherWorker
def perform(feed_onestop_id)
begin
feed = Feed.find_by_onestop_id!(feed_onestop_id)
logger.info "FeedFetcherWorker checking #{feed.onestop_id}"
log "FeedFetcherWorker checking #{feed.onestop_id}"
feed_version = FeedFetcherService.fetch_and_return_feed_version(feed)
if feed_version
logger.info "FeedFetcherWorker checked #{feed.onestop_id} and found sha1: #{feed_version.sha1}"
log "FeedFetcherWorker checked #{feed.onestop_id} and found sha1: #{feed_version.sha1}"
else
logger.info "FeedFetcherWorker checked #{feed.onestop_id} and didn't return a FeedVersion"
log "FeedFetcherWorker checked #{feed.onestop_id} and didn't return a FeedVersion"
end
rescue Exception => e
# NOTE: we're catching all exceptions, including Interrupt,
# SignalException, and SyntaxError
logger.error e.message
logger.error e.backtrace
log e.message, :error
log e.backtrace, :error
Raven.capture_exception(e) if defined?(Raven)
end
end
Expand Down