mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-05 16:24:21 +01:00
37 lines
1.2 KiB
Ruby
37 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# Asynchronously synchronize the projects with OpenLab-Projects
|
|
class OpenlabWorker
|
|
include Sidekiq::Worker
|
|
sidekiq_options queue: 'default', retry: true
|
|
|
|
def initialize
|
|
client = Openlab::Client.new(app_secret: Setting.get('openlab_app_secret'))
|
|
@projects = Openlab::Projects.new(client)
|
|
super
|
|
end
|
|
|
|
def perform(action, project_id)
|
|
logger.debug ['Openlab sync', action, "project ID: #{project_id}"]
|
|
|
|
case action.to_s
|
|
when /create/
|
|
project = Project.find(project_id)
|
|
response = @projects.create(project.openlab_attributes)
|
|
when /update/
|
|
project = Project.find(project_id)
|
|
response = @projects.update(project_id, project.openlab_attributes)
|
|
when /destroy/
|
|
response = @projects.destroy(project_id)
|
|
else
|
|
raise NotImplementedError
|
|
end
|
|
|
|
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?
|
|
rescue ActiveRecord::RecordNotFound => e
|
|
logger.warn "#{e.message}: Project #{project_id} was not found, unable to sync it on OpenLab"
|
|
end
|
|
end
|