~free.ekanayaka/landscape-client/maverick-1.5.4-0ubuntu0.10.10.0

« back to all changes in this revision

Viewing changes to landscape/package/taskhandler.py

  • Committer: Bazaar Package Importer
  • Author(s): Free Ekanayaka
  • Date: 2010-02-10 18:50:53 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20100210185053-kqyzavz3rkpkl7nx
Tags: 1.4.4-0ubuntu0.10.04
* New upstream release (LP: #519200):
  - Add a message for creating package locks (LP: #514334)
  - Add support for auto-approved change-packages messages (LP: #517175)
  - Add support for installing server-generated debian packages (LP: #509752)
  - Add support for reporting Eucalyptus topology information (LP: #518501)
  - Fix timeout while inserting large free-space message (LP: #218388)
  - Fix wrong log path in motd (LP: #517454)
  - Fix race condition in process excecution (LP: #517453)

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
from landscape.broker.remote import RemoteBroker
13
13
 
14
14
 
 
15
class PackageTaskError(Exception):
 
16
    """Raised when a task hasn't been successfully completed."""
 
17
 
 
18
 
15
19
class PackageTaskHandlerConfiguration(Configuration):
16
20
    """Specialized configuration for L{PackageTaskHandler}s."""
17
21
 
66
70
        self._facade = package_facade
67
71
        self._broker = remote_broker
68
72
        self._config = config
69
 
        self._channels_reloaded = False
70
 
 
71
 
    def ensure_channels_reloaded(self):
72
 
        if not self._channels_reloaded:
73
 
            self._channels_reloaded = True
74
 
            self._facade.reload_channels()
 
73
        self._count = 0
75
74
 
76
75
    def run(self):
77
76
        return self.handle_tasks()
78
77
 
79
78
    def handle_tasks(self):
 
79
        """Handle the tasks in the queue.
 
80
 
 
81
        The tasks will be handed over one by one to L{handle_task} until the
 
82
        queue is empty or a task fails.
 
83
 
 
84
        @see: L{handle_tasks}
 
85
        """
80
86
        return self._handle_next_task(None)
81
87
 
82
88
    def _handle_next_task(self, result, last_task=None):
 
89
        """Pick the next task from the queue and pass it to C{handle_task}."""
 
90
 
83
91
        if last_task is not None:
84
92
            # Last task succeeded.  We can safely kill it now.
85
93
            last_task.remove()
 
94
            self._count += 1
86
95
 
87
96
        task = self._store.get_next_task(self.queue_name)
88
97
 
89
98
        if task:
90
99
            # We have another task.  Let's handle it.
91
100
            result = self.handle_task(task)
92
 
            result.addCallback(self._handle_next_task, task)
 
101
            result.addCallback(self._handle_next_task, last_task=task)
 
102
            result.addErrback(self._handle_task_failure)
93
103
            return result
94
104
 
95
105
        else:
96
106
            # No more tasks!  We're done!
97
107
            return succeed(None)
98
108
 
 
109
    def _handle_task_failure(self, failure):
 
110
        """Gracefully handle a L{PackageTaskError} and stop handling tasks."""
 
111
        failure.trap(PackageTaskError)
 
112
 
99
113
    def handle_task(self, task):
 
114
        """Handle a sigle task.
 
115
 
 
116
        Sub-classes must override this method in order to trigger task-specific
 
117
        actions.
 
118
 
 
119
        This method must return a L{Deferred} firing the task result. If the
 
120
        deferred is successful the task will be removed from the queue and the
 
121
        next one will be picked. If the task can't be completed, this method
 
122
        must raise a L{PackageTaskError}, in this case the handler will stop
 
123
        processing tasks and the failed task won't be removed from the queue.
 
124
        """
100
125
        return succeed(None)
101
126
 
 
127
    @property
 
128
    def handled_tasks_count(self):
 
129
        """
 
130
        Return the number of tasks that have been successfully handled so far.
 
131
        """
 
132
        return self._count
 
133
 
102
134
    def use_hash_id_db(self):
103
135
        """
104
136
        Attach the appropriate pre-canned hash=>id database to our store.