~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/codehosting/puller/scheduler.py

  • Committer: Robert Collins
  • Date: 2011-10-17 05:41:34 UTC
  • mto: This revision was merged to the branch mainline in revision 14213.
  • Revision ID: robertc@robertcollins.net-20111017054134-m1bo7gi6s6aixc7h
Nuke setOopsToken unneeded in a concurrency safe world.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
from lp.code.interfaces.codehosting import LAUNCHPAD_SERVICES
40
40
from lp.codehosting.puller import get_lock_id_for_branch_id
41
41
from lp.codehosting.puller.worker import get_canonical_url_for_branch_name
42
 
from lp.services.propertycache import cachedproperty
43
42
from lp.services.twistedsupport.processmonitor import (
44
43
    ProcessMonitorProtocolWithTimeout,
45
44
    )
286
285
    protocol_class = PullerMonitorProtocol
287
286
 
288
287
    def __init__(self, branch_id, source_url, unique_name, branch_type_name,
289
 
                 default_stacked_on_url, logger, client,
290
 
                 available_oops_prefixes):
 
288
                 default_stacked_on_url, logger, client):
291
289
        """Construct a PullerMaster object.
292
290
 
293
291
        :param branch_id: The database ID of the branch to be mirrored.
302
300
        :param logger: A Python logging object.
303
301
        :param client: An asynchronous client for the branch status XML-RPC
304
302
            service.
305
 
        :param available_oops_prefixes: A set of OOPS prefixes to pass out to
306
 
            worker processes. The purpose is to ensure that there are no
307
 
            collisions in OOPS prefixes between currently-running worker
308
 
            processes.
309
303
        """
310
304
        self.branch_id = branch_id
311
305
        self.source_url = source_url.strip()
315
309
        self.default_stacked_on_url = default_stacked_on_url
316
310
        self.logger = logger
317
311
        self.codehosting_endpoint = client
318
 
        self._available_oops_prefixes = available_oops_prefixes
319
 
 
320
 
    @cachedproperty
321
 
    def oops_prefix(self):
322
 
        """Allocate and return an OOPS prefix for the worker process."""
323
 
        try:
324
 
            return self._available_oops_prefixes.pop()
325
 
        except KeyError:
326
 
            self.unexpectedError(failure.Failure())
327
 
            raise
328
 
 
329
 
    def releaseOopsPrefix(self, pass_through=None):
330
 
        """Release the OOPS prefix allocated to this worker.
331
 
 
332
 
        :param pass_through: An unused parameter that is returned unmodified.
333
 
            Useful for adding this method as a Twisted callback / errback.
334
 
        """
335
 
        self._available_oops_prefixes.add(self.oops_prefix)
336
 
        return pass_through
337
312
 
338
313
    def mirror(self):
339
314
        """Spawn a worker process to mirror a branch."""
343
318
        command = [
344
319
            interpreter, self.path_to_script, self.source_url,
345
320
            self.destination_url, str(self.branch_id), str(self.unique_name),
346
 
            self.branch_type_name, self.oops_prefix,
 
321
            self.branch_type_name,
347
322
            self.default_stacked_on_url]
348
323
        self.logger.debug("executing %s", command)
349
324
        env = os.environ.copy()
362
337
        """
363
338
        deferred = self.mirror()
364
339
        deferred.addErrback(self.unexpectedError)
365
 
        deferred.addBoth(self.releaseOopsPrefix)
366
340
        return deferred
367
341
 
368
342
    def startMirroring(self):
429
403
        self.name = 'branch-puller'
430
404
        self.lockfilename = '/var/lock/launchpad-%s.lock' % self.name
431
405
 
432
 
    @cachedproperty
433
 
    def available_oops_prefixes(self):
434
 
        """Generate and return a set of OOPS prefixes for worker processes.
435
 
 
436
 
        This set will contain at most config.supermirror.maximum_workers
437
 
        elements. It's expected that the contents of the set will be modified
438
 
        by `PullerMaster` objects.
439
 
        """
440
 
        return set(
441
 
            [str(i) for i in range(config.supermirror.maximum_workers)])
442
 
 
443
406
    def _turnJobTupleIntoTask(self, job_tuple):
444
407
        """Turn the return value of `acquireBranchToPull` into a job.
445
408
 
455
418
        master = PullerMaster(
456
419
            branch_id, pull_url, unique_name, branch_type_name,
457
420
            default_stacked_on_url, self.logger,
458
 
            self.codehosting_endpoint, self.available_oops_prefixes)
 
421
            self.codehosting_endpoint)
459
422
        return master.run
460
423
 
461
424
    def _poll(self):