| 89 | |
| 90 | |
| 91 | Future<Nothing> GarbageCollectorProcess::schedule( |
| 92 | const Duration& d, |
| 93 | const string& path) |
| 94 | { |
| 95 | LOG(INFO) << "Scheduling '" << path << "' for gc " << d << " in the future"; |
| 96 | |
| 97 | // If there's an existing schedule for this path, we must remove |
| 98 | // it here in order to reschedule. |
| 99 | if (timeouts.contains(path)) { |
| 100 | return unschedule(path) |
| 101 | .then(defer( |
| 102 | self(), |
| 103 | &Self::schedule, |
| 104 | d, |
| 105 | path)); |
| 106 | } |
| 107 | |
| 108 | Timeout removalTime = Timeout::in(d); |
| 109 | |
| 110 | timeouts[path] = removalTime; |
| 111 | |
| 112 | Owned<PathInfo> info(new PathInfo(path)); |
| 113 | |
| 114 | paths.put(removalTime, info); |
| 115 | |
| 116 | // If the timer is not yet initialized or the timeout is sooner than |
| 117 | // the currently active timer, update it. |
| 118 | if (timer.timeout().remaining() == Seconds(0) || |
| 119 | removalTime < timer.timeout()) { |
| 120 | reset(); // Schedule the timer for next event. |
| 121 | } |
| 122 | |
| 123 | return info->promise.future(); |
| 124 | } |
| 125 | |
| 126 | |
| 127 | Future<bool> GarbageCollectorProcess::unschedule(const string& path) |