diff options
author | Brent Eagles <beagles@redhat.com> | 2013-02-18 11:16:59 -0330 |
---|---|---|
committer | Brent Eagles <beagles@redhat.com> | 2013-02-19 16:55:47 -0330 |
commit | d5233d17706148a821c9ca3022ae63c74e9c8748 (patch) | |
tree | c1d58d2cd0946ef51ad1aa0118c844bbe717a518 /nova/manager.py | |
parent | 931515378cfb893a8d15d06b25216fe9242f53b6 (diff) | |
download | nova-d5233d17706148a821c9ca3022ae63c74e9c8748.tar.gz nova-d5233d17706148a821c9ca3022ae63c74e9c8748.tar.xz nova-d5233d17706148a821c9ca3022ae63c74e9c8748.zip |
Support running periodic tasks immediately at startup
This change adds a parameter to allow periodic tasks that would
otherwise have to wait for a lengthy initial interval to run immediately
when the periodic tasks are started. This patch also applies the new
facility in the the _sync_power_states task in the compute manager to
get more timely access to Openstack server state when the compute node
starts up.
Change-Id: I461a5dbaa7d18919941ec31402910eef188d8e8c
Diffstat (limited to 'nova/manager.py')
-rw-r--r-- | nova/manager.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/nova/manager.py b/nova/manager.py index 7c7cbeb67..a0269d30b 100644 --- a/nova/manager.py +++ b/nova/manager.py @@ -88,9 +88,15 @@ def periodic_task(*args, **kwargs): 1. Without arguments '@periodic_task', this will be run on every cycle of the periodic scheduler. - 2. With arguments, @periodic_task(periodic_spacing=N), this will be - run on approximately every N seconds. If this number is negative the - periodic task will be disabled. + 2. With arguments: + @periodic_task(spacing=N [, run_immediately=[True|False]]) + this will be run on approximately every N seconds. If this number is + negative the periodic task will be disabled. If the run_immediately + argument is provided and has a value of 'True', the first run of the + task will be shortly after task scheduler starts. If + run_immediately is omitted or set to 'False', the first time the + task runs will be approximately N seconds after the task scheduler + starts. """ def decorator(f): # Test for old style invocation @@ -107,7 +113,10 @@ def periodic_task(*args, **kwargs): # Control frequency f._periodic_spacing = kwargs.pop('spacing', 0) - f._periodic_last_run = time.time() + if kwargs.pop('run_immediately', False): + f._periodic_last_run = None + else: + f._periodic_last_run = time.time() return f # NOTE(sirp): The `if` is necessary to allow the decorator to be used with @@ -213,6 +222,8 @@ class Manager(base.Base): # If a periodic task is _nearly_ due, then we'll run it early if self._periodic_spacing[task_name] is None: wait = 0 + elif self._periodic_last_run[task_name] is None: + wait = 0 else: due = (self._periodic_last_run[task_name] + self._periodic_spacing[task_name]) |