diff --git a/Procfile b/Procfile index bbb53736..347e81f3 100644 --- a/Procfile +++ b/Procfile @@ -1,2 +1,3 @@ web: bundle exec ./script/server console: bundle exec ./script/console +sidekiq: bundle exec sidekiq -c 5 -r ./lib/travis/sidekiq.rb -q build_cancellations diff --git a/lib/travis/api/app/endpoint/builds.rb b/lib/travis/api/app/endpoint/builds.rb index 2f1e5837..d38d5fe3 100644 --- a/lib/travis/api/app/endpoint/builds.rb +++ b/lib/travis/api/app/endpoint/builds.rb @@ -37,7 +37,9 @@ class Travis::Api::App status 422 respond_with json else - service.run + #service.run + #check syntax of line below + Travis::Sidekiq::BuildCancellation.perform_async(params.merge(source: 'api')) Metriks.meter("api.request.cancel_build.success").mark status 204 diff --git a/lib/travis/api/workers/build_cancellation.rb b/lib/travis/api/workers/build_cancellation.rb new file mode 100644 index 00000000..be19d31b --- /dev/null +++ b/lib/travis/api/workers/build_cancellation.rb @@ -0,0 +1,29 @@ +require 'sidekiq/worker' +require 'multi_json' + +module Travis + module Sidekiq + class BuildCancellation + class ProcessingError < StandardError; end + + include ::Sidekiq::Worker + # do we need to name the queue here? we didn't do this in Admin. We passed this info in the procfile + sidekiq_options queue: build_cancellations + + attr_accessor :data + + def perform(data) + @data = data + if payload + service.run + else + Travis.logger.warn("The #{type} payload was empty and could not be processed") + end + end + + def service + @service ||= Travis.service(:cancel_build, data) + end + end + end +end \ No newline at end of file diff --git a/lib/travis/sidekiq.rb b/lib/travis/sidekiq.rb new file mode 100644 index 00000000..3f871713 --- /dev/null +++ b/lib/travis/sidekiq.rb @@ -0,0 +1,7 @@ +$: << './lib' +require 'travis/core' +require 'travis/app/workers/build_cancellation' + +Sidekiq.configure_server do |config| + config.redis = Travis.config.redis.merge(namespace: Travis.config.sidekiq.namespace) +end \ No newline at end of file