app/models/kuroko2/job_definition.rb in kuroko2-0.2.3 vs app/models/kuroko2/job_definition.rb in kuroko2-0.3.0

- old
+ new

@@ -75,10 +75,11 @@ validates :hipchat_additional_text, length: { maximum: 180 } validates :slack_channel, length: { maximum: 21 }, format: { with: /\A#[^\.\s]+\z/, allow_blank: true, message: ' must start with # and must not include any dots or spaces' } + validates :webhook_url, format: { with: /\A#{URI::regexp(%w(http https))}\z/, allow_blank: true } def proceed_multi_instance? tokens = Kuroko2::Token.where(job_definition_id: self.id) (tokens.map(&:status) & PREVENT_TOKEN_STATUSES[self.prevent_multi]).empty? end @@ -89,9 +90,19 @@ def text_tags=(text_tags) self.tags = text_tags.gsub(/[[:blank:]]+/, '').split(/[,、]/).uniq.map do |name| Kuroko2::Tag.find_or_create_by(name: name) end + end + + def create_instance(script: nil, launched_by:, token: nil ) + message = "Launched by #{launched_by}" + + if token.present? + message = "(token #{token.uuid}) #{message}" + end + + job_instances.create!(script: script, log_message: message) end private def confirm_active_instances