diff options
author | Shinya Maeda <shinya@gitlab.com> | 2019-01-17 09:06:37 +0300 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2019-01-24 14:50:42 +0300 |
commit | 3cc3650dfee5132c120b2b418918f12b3eebcde2 (patch) | |
tree | 0497feec4829ed16e0b0d37954b0998a4d8fac15 /lib/gitlab/loop_helpers.rb | |
parent | 490eeb5159945107576c756b22c08f99b45a8463 (diff) |
Remove expired artifacts periodically
Rename
Introduce Destroy expired job artifacts service
Revert a bit
Add changelog
Use expired
Improve
Fix spec
Fix spec
Use bang for destroy
Introduce iteration limit
Update comment
Simplify more
Refacor
Remove unnecessary thing
Fix comments
Fix coding offence
Make loop helper exception free
Diffstat (limited to 'lib/gitlab/loop_helpers.rb')
-rw-r--r-- | lib/gitlab/loop_helpers.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/gitlab/loop_helpers.rb b/lib/gitlab/loop_helpers.rb new file mode 100644 index 00000000000..3873156a3b0 --- /dev/null +++ b/lib/gitlab/loop_helpers.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module Gitlab + module LoopHelpers + ## + # This helper method repeats the same task until it's expired. + # + # Note: ExpiredLoopError does not happen until the given block finished. + # Please do not use this method for heavy or asynchronous operations. + def loop_until(timeout: nil, limit: 1_000_000) + raise ArgumentError unless limit + + start = Time.now + + limit.times do + return true unless yield + + return false if timeout && (Time.now - start) > timeout + end + + false + end + end +end |