diff options
author | Mike Greiling <mike@pixelcog.com> | 2017-08-07 22:44:47 -0500 |
---|---|---|
committer | Mike Greiling <mike@pixelcog.com> | 2017-08-07 22:44:47 -0500 |
commit | 0994bbf9dd79413b3c22381bc2d82fcc41aa13bc (patch) | |
tree | 4488184f950fb66ae761209952722bb72bf18b72 /lib/gitlab/daemon.rb | |
parent | 1375db509a4cd30d759d588ee85a8aec2771d78a (diff) | |
parent | 9e7ac48bc11141762816f157247baaf9e61618b3 (diff) | |
download | gitlab-ce-0994bbf9dd79413b3c22381bc2d82fcc41aa13bc.tar.gz |
Merge branch 'master' into ide
* master: (86 commits)
Show all labels
33874 confidential issue redesign
Exclude merge_jid on Import/Export attribute configuration
Resolve "User dropdown in filtered search does not load avatar on `master`"
Re-add column locked_at on migration rollback
Group-level new issue & MR using previously selected project
[EE Backport] Update log audit event in omniauth_callbacks_controller.rb
more eagerly bail when the state is prevented
Move locked_at removal to post-deployment migration
Add class to other sidebars
Improve mobile sidebar
reduce iterations by keeping a count of remaining enablers
Store & use ConvDev percentages returned by Version app
Store MergeWorker JID on merge request, and clean up stuck merges
Backport changes in https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/2551 to CE
DRY up caching in AbstractReferenceFilter
Update CHANGELOG
Add CHANGELOG entry
Fix html structure Removes test for removed behavior
Port form back to use form_tag
...
Diffstat (limited to 'lib/gitlab/daemon.rb')
-rw-r--r-- | lib/gitlab/daemon.rb | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/gitlab/daemon.rb b/lib/gitlab/daemon.rb new file mode 100644 index 00000000000..dfd17e35707 --- /dev/null +++ b/lib/gitlab/daemon.rb @@ -0,0 +1,62 @@ +module Gitlab + class Daemon + def self.initialize_instance(*args) + raise "#{name} singleton instance already initialized" if @instance + @instance = new(*args) + Kernel.at_exit(&@instance.method(:stop)) + @instance + end + + def self.instance + @instance ||= initialize_instance + end + + attr_reader :thread + + def thread? + !thread.nil? + end + + def initialize + @mutex = Mutex.new + end + + def enabled? + true + end + + def start + return unless enabled? + + @mutex.synchronize do + return thread if thread? + + @thread = Thread.new { start_working } + end + end + + def stop + @mutex.synchronize do + return unless thread? + + stop_working + + if thread + thread.wakeup if thread.alive? + thread.join + @thread = nil + end + end + end + + private + + def start_working + raise NotImplementedError + end + + def stop_working + # no-ops + end + end +end |