1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-11 22:24:21 +01:00
fab-manager/app/workers/openlab_worker.rb

35 lines
1.1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
# Asynchronously synchronize the projects with OpenLab-Projects
2016-04-20 18:13:36 +02:00
class OpenlabWorker
include Sidekiq::Worker
sidekiq_options queue: 'default', retry: true
def initialize
client = Openlab::Client.new(app_secret: Setting.get('openlab_app_secret'))
@projets = Openlab::Projects.new(client)
super
end
2016-04-20 18:13:36 +02:00
def perform(action, project_id)
2020-06-09 18:51:57 +02:00
logger.debug ['Openlab sync', action, "project ID: #{project_id}"]
2016-04-20 18:13:36 +02:00
case action.to_s
when /create/
project = Project.find(project_id)
response = @projets.create(project.openlab_attributes)
2016-04-20 18:13:36 +02:00
when /update/
project = Project.find(project_id)
response = @projets.update(project_id, project.openlab_attributes)
2016-04-20 18:13:36 +02:00
when /destroy/
response = @projets.destroy(project_id)
else
raise NotImplementedError
2016-04-20 18:13:36 +02:00
end
2020-06-09 18:51:57 +02:00
logger.debug ['Openlab sync', 'RESPONSE ERROR', response.inspect] unless response.success?
rescue Errno::ECONNREFUSED => e
logger.warn "Unable to connect to OpenProject, maybe the dev instance is not running: #{e}" if Rails.env.development?
2016-04-20 18:13:36 +02:00
end
end