def edit_strike(self, strike_id, title=None, description=None, configuration=None): """Edits the given Strike process and saves the changes in the database. All database changes occur in an atomic transaction. An argument of None for a field indicates that the field should not change. :param strike_id: The unique identifier of the Strike process to edit :type strike_id: int :param title: The human-readable name of this Strike process :type title: string :param description: A description of this Strike process :type description: string :param configuration: The Strike process configuration :type configuration: dict :raises :class:`ingest.strike.configuration.exceptions.InvalidStrikeConfiguration`: If the configuration is invalid. """ strike = Strike.objects.get(pk=strike_id) # Validate the configuration, no exception is success if configuration: config = StrikeConfiguration(configuration) config.validate() strike.configuration = config.get_dict() # Update editable fields if title: strike.title = title if description: strike.description = description strike.save()
def edit_strike(self, strike_id, title=None, description=None, configuration=None): """Edits the given Strike process and saves the changes in the database. All database changes occur in an atomic transaction. An argument of None for a field indicates that the field should not change. :param strike_id: The unique identifier of the Strike process to edit :type strike_id: int :param title: The human-readable name of this Strike process :type title: string :param description: A description of this Strike process :type description: string :param configuration: The Strike process configuration :type configuration: dict :raises :class:`ingest.strike.configuration.exceptions.InvalidStrikeConfiguration`: If the configuration is invalid. """ strike = Strike.objects.get(pk=strike_id) # Validate the configuration, no exception is success if configuration: config = StrikeConfiguration(configuration) config.validate() strike.configuration = config.get_dict() # Update editable fields if title: strike.title = title if description: strike.description = description strike.save()
def create_strike(self, name, title, description, configuration): """Creates a new Strike process with the given configuration and returns the new Strike model. The Strike model will be saved in the database and the job to run the Strike process will be placed on the queue. All changes to the database will occur in an atomic transaction. :param name: The identifying name of this Strike process :type name: string :param title: The human-readable name of this Strike process :type title: string :param description: A description of this Strike process :type description: string :param configuration: The Strike configuration :type configuration: dict :returns: The new Strike process :rtype: :class:`ingest.models.Strike` :raises :class:`ingest.strike.configuration.exceptions.InvalidStrikeConfiguration`: If the configuration is invalid. """ # Validate the configuration, no exception is success config = StrikeConfiguration(configuration) config.validate() strike = Strike() strike.name = name strike.title = title strike.description = description strike.configuration = config.get_dict() strike.save() strike_type = self.get_strike_job_type() job_data = JobData() job_data.add_property_input('Strike ID', unicode(strike.id)) event_description = {'strike_id': strike.id} event = TriggerEvent.objects.create_trigger_event( 'STRIKE_CREATED', None, event_description, now()) strike.job = Queue.objects.queue_new_job(strike_type, job_data, event) strike.save() return strike
def create_strike(self, name, title, description, configuration): """Creates a new Strike process with the given configuration and returns the new Strike model. The Strike model will be saved in the database and the job to run the Strike process will be placed on the queue. All changes to the database will occur in an atomic transaction. :param name: The identifying name of this Strike process :type name: string :param title: The human-readable name of this Strike process :type title: string :param description: A description of this Strike process :type description: string :param configuration: The Strike configuration :type configuration: dict :returns: The new Strike process :rtype: :class:`ingest.models.Strike` :raises :class:`ingest.strike.configuration.exceptions.InvalidStrikeConfiguration`: If the configuration is invalid. """ # Validate the configuration, no exception is success config = StrikeConfiguration(configuration) config.validate() strike = Strike() strike.name = name strike.title = title strike.description = description strike.configuration = config.get_dict() strike.save() strike_type = self.get_strike_job_type() job_data = JobData() job_data.add_property_input('Strike ID', unicode(strike.id)) event_description = {'strike_id': strike.id} event = TriggerEvent.objects.create_trigger_event('STRIKE_CREATED', None, event_description, now()) strike.job = Queue.objects.queue_new_job(strike_type, job_data, event) strike.save() return strike