Extend rake task to run with cron

pull/6827/head
Oliver Günther 7 years ago
parent 309e966418
commit c48c5c75d3
No known key found for this signature in database
GPG Key ID: 88872239EB414F99
  1. 21
      lib/tasks/ldap_groups.rake

@ -31,10 +31,23 @@ namespace :ldap_groups do
desc 'Synchronize groups and their users from the LDAP auth source.' \
'Will only synchronize for those users already present in the application.'
task synchronize: :environment do
LdapAuthSource.find_each do |ldap|
puts ("-" * 20)
puts "Synchronizing for ldap auth source #{ldap.name}"
OpenProject::LdapGroups::Synchronization.new(ldap)
begin
LdapAuthSource.find_each do |ldap|
puts ("-" * 20)
puts "Synchronizing for ldap auth source #{ldap.name}"
OpenProject::LdapGroups::Synchronization.new(ldap)
end
rescue => e
msg = "Failed to run LDAP group synchronization. #{e.class.name}: #{e.message}"
Rails.logger.error msg
warn msg
end
end
end
# Ensure core cron task is loaded
load 'lib/tasks/cron.rake'
Rake::Task["openproject:cron:hourly"].enhance do
Rake::Task["ldap_groups:synchronize"].invoke
end

Loading…
Cancel
Save