コード例 #1
0
ファイル: tasks.py プロジェクト: topherlandry/CumulusCI
class SchedulePushOrgList(BaseSalesforcePushTask):

    task_options = {
        'orgs': {
            'description': 'The path to a file containing one OrgID per line.',
            'required': True,
        },
        'version': {
            'description': 'The managed package version to push',
            'required': True,
        },
        'namespace': {
            'description': ('The managed package namespace to push.' +
                            ' Defaults to project__package__namespace.')
        },
        'start_time': {
            'description':
            ('Set the start time (UTC) to queue a future push.' +
             ' Ex: 2016-10-19T10:00')
        },
        'batch_size': {
            'description':
            ('Break pull requests into batches of this many orgs.' +
             ' Defaults to 200.')
        },
    }

    def _init_task(self):
        super(SchedulePushOrgList, self)._init_task()
        self.push = SalesforcePushApi(
            self.sf,
            self.logger,
            self.options['batch_size'],
        )

    def _init_options(self, kwargs):
        super(SchedulePushOrgList, self)._init_options(kwargs)

        # Set the namespace option to the value from cumulusci.yml if not
        # already set
        if not 'namespace' in self.options:
            self.options['namespace'] = (
                self.project_config.project__package__namespace)
        if not 'batch_size' in self.options:
            self.options['batch_size'] = 200

    def _get_orgs(self):
        return self._load_orgs_file(self.options.get('orgs'))

    def _run_task(self):
        orgs = self._get_orgs()
        package = self._get_package(self.options.get('namespace'))
        version = self._get_version(package, self.options.get('version'))

        start_time = self.options.get('start_time')
        if start_time:
            if start_time.lower() == 'now':
                start_time = datetime.utcnow() + timedelta(seconds=5)
            else:
                start_time = datetime.strptime(start_time, '%Y-%m-%dT%H:%M')
            if start_time < datetime.utcnow():
                raise CumulusCIException('Start time cannot be in the past')
        else:
            # delay a bit to allow for review
            delay_minutes = 5
            self.logger.warn(
                'Scheduling push for %d minutes from now',
                delay_minutes,
            )
            start_time = datetime.utcnow() + timedelta(minutes=delay_minutes)

        self.request_id, num_scheduled_orgs = self.push.create_push_request(
            version,
            orgs,
            start_time,
        )

        self.return_values['request_id'] = self.request_id

        if num_scheduled_orgs > 1000:
            sleep_time_s = 30
            self.logger.info(
                'Delaying {} seconds to allow all jobs to initialize'.format(
                    sleep_time_s))
            time.sleep(sleep_time_s)
        elif num_scheduled_orgs == 0:
            self.logger.warn('Canceling push request with 0 orgs')
            self.push.cancel_push_request
            return

        self.logger.info('Setting status to Pending to queue execution.')
        self.logger.info(
            'The push upgrade will start at UTC {}'.format(start_time))

        # Run the job
        self.logger.info(self.push.run_push_request(self.request_id))
        self.logger.info('Push Request {} is queued for execution.'.format(
            self.request_id))

        # Report the status if start time is less than 1 minute from now
        if start_time - datetime.utcnow() < timedelta(minutes=1):
            self._report_push_status(self.request_id)
        else:
            self.logger.info('Exiting early since request is in the future')
コード例 #2
0
class SchedulePushOrgList(BaseSalesforcePushTask):

    task_options = {
        "orgs": {
            "description": "The path to a file containing one OrgID per line.",
            "required": True,
        },
        "version": {
            "description": "The managed package version to push",
            "required": True,
        },
        "namespace": {
            "description": (
                "The managed package namespace to push."
                + " Defaults to project__package__namespace."
            )
        },
        "start_time": {
            "description": (
                "Set the start time (UTC) to queue a future push."
                + " Ex: 2016-10-19T10:00"
            )
        },
        "batch_size": {
            "description": (
                "Break pull requests into batches of this many orgs."
                + " Defaults to 200."
            )
        },
    }

    def _init_task(self):
        super(SchedulePushOrgList, self)._init_task()
        self.push = SalesforcePushApi(self.sf, self.logger, self.options["batch_size"])

    def _init_options(self, kwargs):
        super(SchedulePushOrgList, self)._init_options(kwargs)

        # Set the namespace option to the value from cumulusci.yml if not
        # already set
        if not "namespace" in self.options:
            self.options["namespace"] = self.project_config.project__package__namespace
        if not "batch_size" in self.options:
            self.options["batch_size"] = 200

    def _get_orgs(self):
        return self._load_orgs_file(self.options.get("orgs"))

    def _run_task(self):
        orgs = self._get_orgs()
        package = self._get_package(self.options.get("namespace"))
        version = self._get_version(package, self.options.get("version"))

        start_time = self.options.get("start_time")
        if start_time:
            if start_time.lower() == "now":
                start_time = datetime.utcnow() + timedelta(seconds=5)
            else:
                start_time = datetime.strptime(start_time, "%Y-%m-%dT%H:%M")
            if start_time < datetime.utcnow():
                raise CumulusCIException("Start time cannot be in the past")
        else:
            # delay a bit to allow for review
            delay_minutes = 5
            self.logger.warning(
                "Scheduling push for %d minutes from now", delay_minutes
            )
            start_time = datetime.utcnow() + timedelta(minutes=delay_minutes)

        self.request_id, num_scheduled_orgs = self.push.create_push_request(
            version, orgs, start_time
        )

        self.return_values["request_id"] = self.request_id

        if num_scheduled_orgs > 1000:
            sleep_time_s = 30
            self.logger.info(
                "Delaying {} seconds to allow all jobs to initialize".format(
                    sleep_time_s
                )
            )
            time.sleep(sleep_time_s)
        elif num_scheduled_orgs == 0:
            self.logger.warning("Canceling push request with 0 orgs")
            self.push.cancel_push_request
            return

        self.logger.info("Setting status to Pending to queue execution.")
        self.logger.info("The push upgrade will start at UTC {}".format(start_time))

        # Run the job
        self.logger.info(self.push.run_push_request(self.request_id))
        self.logger.info(
            "Push Request {} is queued for execution.".format(self.request_id)
        )

        # Report the status if start time is less than 1 minute from now
        if start_time - datetime.utcnow() < timedelta(minutes=1):
            self._report_push_status(self.request_id)
        else:
            self.logger.info("Exiting early since request is in the future")
コード例 #3
0
class SchedulePushOrgList(BaseSalesforcePushTask):

    task_options = {
        "csv": {"description": "The path to a CSV file to read.", "required": False},
        "csv_field_name": {
            "description": "The CSV field name that contains organization IDs. Defaults to 'OrganizationID'",
            "required": False,
        },
        "orgs": {
            "description": "The path to a file containing one OrgID per line.",
            "required": False,
        },
        "version": {
            "description": "The managed package version to push",
            "required": True,
        },
        "namespace": {
            "description": (
                "The managed package namespace to push."
                + " Defaults to project__package__namespace."
            )
        },
        "start_time": {
            "description": (
                "Set the start time (UTC) to queue a future push."
                + " Ex: 2016-10-19T10:00"
            )
        },
        "batch_size": {
            "description": (
                "Break pull requests into batches of this many orgs."
                + " Defaults to 200."
            )
        },
    }

    def _init_task(self):
        super(SchedulePushOrgList, self)._init_task()
        self.push = SalesforcePushApi(self.sf, self.logger, self.options["batch_size"])

    def _init_options(self, kwargs):
        super(SchedulePushOrgList, self)._init_options(kwargs)

        neither_file_option = "orgs" not in self.options and "csv" not in self.options
        both_file_options = "orgs" in self.options and "csv" in self.options
        if neither_file_option or both_file_options:
            raise TaskOptionsError(
                "Please call this task with either the `orgs` or `csv` option."
            )
        # Set the namespace option to the value from cumulusci.yml if not
        # already set
        if "namespace" not in self.options:
            self.options["namespace"] = self.project_config.project__package__namespace
        if "batch_size" not in self.options:
            self.options["batch_size"] = 200
        if "csv" not in self.options and "csv_field_name" in self.options:
            raise TaskOptionsError("Please provide a csv file for this task to run.")

    def _get_orgs(self):
        if "csv" in self.options:
            with open(self.options.get("csv"), newline="", encoding="utf-8") as csvfile:
                reader = csv.DictReader(csvfile)
                return [
                    row[self.options.get("csv_field_name", "OrganizationId")]
                    for row in reader
                ]
        else:
            return self._load_orgs_file(self.options.get("orgs"))

    def _run_task(self):
        orgs = self._get_orgs()
        package = self._get_package(self.options.get("namespace"))
        version = self._get_version(package, self.options.get("version"))

        start_time = self.options.get("start_time")
        if start_time:
            if start_time.lower() == "now":
                start_time = datetime.utcnow() + timedelta(seconds=5)
            else:
                start_time = datetime.strptime(start_time, "%Y-%m-%dT%H:%M")
            if start_time < datetime.utcnow():
                raise CumulusCIException("Start time cannot be in the past")
        else:
            # delay a bit to allow for review
            delay_minutes = 5
            self.logger.warning(
                "Scheduling push for %d minutes from now", delay_minutes
            )
            start_time = datetime.utcnow() + timedelta(minutes=delay_minutes)

        self.request_id, num_scheduled_orgs = self.push.create_push_request(
            version, orgs, start_time
        )

        self.return_values["request_id"] = self.request_id

        if num_scheduled_orgs > 1000:
            sleep_time_s = 30
            self.logger.info(
                "Delaying {} seconds to allow all jobs to initialize".format(
                    sleep_time_s
                )
            )
            time.sleep(sleep_time_s)
        elif num_scheduled_orgs == 0:
            self.logger.warning("Canceling push request with 0 orgs")
            self.push.cancel_push_request
            return

        self.logger.info("Setting status to Pending to queue execution.")
        self.logger.info("The push upgrade will start at UTC {}".format(start_time))

        # Run the job
        self.logger.info(self.push.run_push_request(self.request_id))
        self.logger.info(
            "Push Request {} is queued for execution.".format(self.request_id)
        )

        # Report the status if start time is less than 1 minute from now
        if start_time - datetime.utcnow() < timedelta(minutes=1):
            self._report_push_status(self.request_id)
        else:
            self.logger.info("Exiting early since request is in the future")
コード例 #4
0
class SchedulePushOrgList(BaseSalesforcePushTask):

    task_options = {
        'orgs': {
            'description': "The path to a file containing one OrgID per line.",
            'required': True,
        },
        'version': {
            'description': "The managed package version to push",
            'required': True,
        },
        'namespace': {
            'description':
            "The managed package namespace to push. Defaults to project__package__namespace.",
        },
        'start_time': {
            'description':
            "Set the start time (UTC) to queue a future push. Ex: 2016-10-19T10:00",
        },
        'batch_size': {
            'description':
            "Set batch size used to add individual orgs to the push request.  Defaults to 200",
        },
    }

    def _init_task(self):
        super(SchedulePushOrgList, self)._init_task()
        self.push = SalesforcePushApi(self.sf, self.logger,
                                      self.options['batch_size'])

    def _init_options(self, kwargs):
        super(SchedulePushOrgList, self)._init_options(kwargs)

        # Set the namespace option to the value from cumulusci.yml if not already set
        if not 'namespace' in self.options:
            self.options[
                'namespace'] = self.project_config.project__package__namespace
        if not 'batch_size' in self.options:
            self.options['batch_size'] = 200

    def _get_orgs(self):
        return self._load_orgs_file(self.options.get('orgs'))

    def _run_task(self):
        orgs = self._get_orgs()
        package = self._get_package(self.options.get('namespace'))
        version = self._get_version(package, self.options.get('version'))

        start_time = self.options.get('start_time')
        if start_time:
            start_time = datetime.strptime(
                start_time, "%Y-%m-%dT%H:%M")  # Example: 2016-10-19T10:00

        self.request_id = self.push.create_push_request(
            version, orgs, start_time)

        if len(orgs) > 1000:
            self.logger.info(
                "Delaying 30 seconds to allow all jobs to initialize...")
            time.sleep(30)

        self.logger.info('Push Request {} is populated with {} orgs'.format(
            self.request_id, len(orgs)))
        self.logger.info('Setting status to Pending to queue execution.')
        if start_time:
            self.logger.info(
                'The push request will start at {}'.format(start_time))

        # Run the job
        self.logger.info(self.push.run_push_request(self.request_id))
        self.logger.info('Push Request {} is queued for execution.'.format(
            self.request_id))

        # Report the status
        self._report_push_status(self.request_id)
コード例 #5
0
ファイル: tasks.py プロジェクト: wilsonmar/CumulusCI
class SchedulePushOrgList(BaseSalesforcePushTask):

    task_options = {
        "orgs": {
            "description": "The path to a file containing one OrgID per line.",
            "required": True,
        },
        "version": {
            "description": "The managed package version to push",
            "required": True,
        },
        "namespace": {
            "description": (
                "The managed package namespace to push."
                + " Defaults to project__package__namespace."
            )
        },
        "start_time": {
            "description": (
                "Set the start time (UTC) to queue a future push."
                + " Ex: 2016-10-19T10:00"
            )
        },
        "batch_size": {
            "description": (
                "Break pull requests into batches of this many orgs."
                + " Defaults to 200."
            )
        },
    }

    def _init_task(self):
        super(SchedulePushOrgList, self)._init_task()
        self.push = SalesforcePushApi(self.sf, self.logger, self.options["batch_size"])

    def _init_options(self, kwargs):
        super(SchedulePushOrgList, self)._init_options(kwargs)

        # Set the namespace option to the value from cumulusci.yml if not
        # already set
        if not "namespace" in self.options:
            self.options["namespace"] = self.project_config.project__package__namespace
        if not "batch_size" in self.options:
            self.options["batch_size"] = 200

    def _get_orgs(self):
        return self._load_orgs_file(self.options.get("orgs"))

    def _run_task(self):
        orgs = self._get_orgs()
        package = self._get_package(self.options.get("namespace"))
        version = self._get_version(package, self.options.get("version"))

        start_time = self.options.get("start_time")
        if start_time:
            if start_time.lower() == "now":
                start_time = datetime.utcnow() + timedelta(seconds=5)
            else:
                start_time = datetime.strptime(start_time, "%Y-%m-%dT%H:%M")
            if start_time < datetime.utcnow():
                raise CumulusCIException("Start time cannot be in the past")
        else:
            # delay a bit to allow for review
            delay_minutes = 5
            self.logger.warn("Scheduling push for %d minutes from now", delay_minutes)
            start_time = datetime.utcnow() + timedelta(minutes=delay_minutes)

        self.request_id, num_scheduled_orgs = self.push.create_push_request(
            version, orgs, start_time
        )

        self.return_values["request_id"] = self.request_id

        if num_scheduled_orgs > 1000:
            sleep_time_s = 30
            self.logger.info(
                "Delaying {} seconds to allow all jobs to initialize".format(
                    sleep_time_s
                )
            )
            time.sleep(sleep_time_s)
        elif num_scheduled_orgs == 0:
            self.logger.warn("Canceling push request with 0 orgs")
            self.push.cancel_push_request
            return

        self.logger.info("Setting status to Pending to queue execution.")
        self.logger.info("The push upgrade will start at UTC {}".format(start_time))

        # Run the job
        self.logger.info(self.push.run_push_request(self.request_id))
        self.logger.info(
            "Push Request {} is queued for execution.".format(self.request_id)
        )

        # Report the status if start time is less than 1 minute from now
        if start_time - datetime.utcnow() < timedelta(minutes=1):
            self._report_push_status(self.request_id)
        else:
            self.logger.info("Exiting early since request is in the future")