Remove unused travis-core services

This commit is contained in:
Ana Rosas 2016-06-30 13:51:47 -07:00 committed by Aakriti Gupta
parent 9b5893b07c
commit 5dd513f79b
4 changed files with 0 additions and 228 deletions

View File

@ -37,8 +37,6 @@ module Travis
end
require 'travis/services/base'
require 'travis/services/cancel_job'
require 'travis/services/cancel_build'
require 'travis/services/delete_caches'
require 'travis/services/find_admin'
require 'travis/services/find_annotations'
@ -63,7 +61,6 @@ require 'travis/services/find_user_permissions'
require 'travis/services/next_build_number'
require 'travis/services/regenerate_repo_key'
require 'travis/services/remove_log'
require 'travis/services/reset_model'
require 'travis/services/sync_user'
require 'travis/services/update_annotation'
require 'travis/services/update_hook'

View File

@ -1,78 +0,0 @@
require 'travis/services/base'
module Travis
module Services
class CancelBuild < Base
extend Travis::Instrumentation
register :cancel_build
attr_reader :source
def initialize(*)
super
@source = params.delete(:source) || 'unknown'
end
def run
cancel if can_cancel?
end
instrument :run
def messages
messages = []
messages << { :notice => 'The build was successfully cancelled.' } if can_cancel?
messages << { :error => 'You are not authorized to cancel this build.' } unless authorized?
messages << { :error => "The build could not be cancelled." } unless build.cancelable?
messages
end
def cancel
# build may have been retrieved with a :join query, so we need to reset the readonly status
build.send(:instance_variable_set, :@readonly, false)
build.cancel!
publish!
end
def publish!
# TODO: I think that instead of keeping publish logic in both cancel build
# and cancel job services, we could call cancel_job service for each job
# in the matrix, which would put build in canceled state, even without calling
# cancel! on build explicitly. This may be a better way to handle cancelling
# build
build.matrix.each do |job|
Travis.logger.info("Publishing cancel_job message to worker.commands queue for Job##{job.id}")
publisher.publish(type: 'cancel_job', job_id: job.id, source: source)
end
end
def can_cancel?
authorized? && build.cancelable?
end
def authorized?
current_user.permission?(:pull, :repository_id => build.repository_id)
end
def build
@build ||= run_service(:find_build, params)
end
def publisher
Travis::Amqp::FanoutPublisher.new('worker.commands')
end
class Instrument < Notification::Instrument
def run_completed
publish(
:msg => "for <Build id=#{target.build.id}> (#{target.current_user.login})",
:result => result
)
end
end
Instrument.attach_to(self)
end
end
end

View File

@ -1,73 +0,0 @@
require 'travis/notification'
require 'travis/services/base'
module Travis
module Services
class CancelJob < Base
extend Travis::Instrumentation
register :cancel_job
attr_reader :source
def initialize(*)
super
@source = params.delete(:source) || 'unknown'
end
def run
cancel if can_cancel?
end
instrument :run
def messages
messages = []
messages << { :notice => 'The job was successfully cancelled.' } if can_cancel?
messages << { :error => 'You are not authorized to cancel this job.' } unless authorized?
messages << { :error => "The job could not be cancelled because it is currently #{job.state}." } unless job.cancelable?
messages
end
def cancel
# job may have been retrieved with a :join query, so we need to reset the readonly status
job.send(:instance_variable_set, :@readonly, false)
publish!
job.cancel!
end
def can_cancel?
authorized? && job.cancelable?
end
def authorized?
current_user.permission?(:pull, :repository_id => job.repository_id)
end
def job
@job ||= run_service(:find_job, params)
end
def publish!
Travis.logger.info("Publishing cancel_job message to worker.commands queue for Job##{job.id}")
publisher.publish(type: 'cancel_job', job_id: job.id, source: source)
end
private
def publisher
Travis::Amqp::FanoutPublisher.new('worker.commands')
end
class Instrument < Notification::Instrument
def run_completed
publish(
:msg => "for <Job id=#{target.job.id}> (#{target.current_user.login})",
:result => result
)
end
end
Instrument.attach_to(self)
end
end
end

View File

@ -1,74 +0,0 @@
require 'travis/support/instrumentation'
require 'travis/services/base'
module Travis
module Services
class ResetModel < Base
extend Travis::Instrumentation
register :reset_model
def run
reset if current_user && target && accept?
true
end
instrument :run
def accept?
current_user && permission? && resetable?
end
def messages
messages = []
messages << { notice: "The #{type} was successfully restarted." } if accept?
messages << { error: 'You do not seem to have sufficient permissions.' } unless permission?
messages << { error: "This #{type} currently can not be restarted." } unless resetable?
messages
end
def type
@type ||= params[:build_id] ? :build : :job
end
def id
@id ||= params[:"#{type}_id"]
end
private
def reset
# target may have been retrieved with a :join query, so we need to reset the readonly status
target.send(:instance_variable_set, :@readonly, false)
target.reset!(reset_matrix: type == :build)
end
def permission?
current_user.permission?(required_role, repository_id: target.repository_id)
end
def resetable?
defined?(@resetable) ? @resetable : @resetable = target.resetable?
end
def required_role
Travis.config.roles.reset_model
end
def target
@target ||= service(:"find_#{type}", id: id).run
end
class Instrument < Notification::Instrument
def run_completed
publish(
msg: "build_id=#{target.id} #{target.accept? ? 'accepted' : 'not accepted'}",
type: target.type,
id: target.id,
accept?: target.accept?
)
end
end
Instrument.attach_to(self)
end
end
end