4 include CommonApiTemplate
5 serialize :command_parameters, Hash
6 serialize :tasks_summary, Hash
7 before_create :ensure_unique_submit_id
9 class SubmitIdReused < StandardError
12 api_accessible :superuser, :extend => :common do |t|
16 t.add :command_parameters
17 t.add :command_version
19 t.add :cancelled_by_client
20 t.add :cancelled_by_user
32 update_attributes(finished_at: finished_at || Time.now,
33 success: success.nil? ? false : success,
39 def ensure_unique_submit_id
41 if Job.where('submit_id=?',self.submit_id).first
42 raise SubmitIdReused.new
50 self.command_parameters.values.each do |v|
51 v.match(/^(([0-9a-f]{32})\b(\+[^,]+)?,?)*$/) do |locator|
52 bare_locator = locator[0].gsub(/\+[^,]+/,'')
53 deps[bare_locator] = true
59 def permission_to_update
60 if is_locked_by_was and !(current_user and
61 current_user.uuid == is_locked_by_was)
62 if command_changed? or
63 command_parameters_changed? or
64 command_version_changed? or
65 cancelled_by_client_changed? or
66 cancelled_by_user_changed? or
67 cancelled_at_changed? or
68 started_at_changed? or
69 finished_at_changed? or
74 tasks_summary_changed?
75 logger.warn "User #{current_user.uuid if current_user} tried to change protected job attributes on locked #{self.class.to_s} #{uuid_was}"
79 if !is_locked_by_changed?
83 logger.warn "Anonymous user tried to change lock on #{self.class.to_s} #{uuid_was}"
85 elsif is_locked_by_was and is_locked_by_was != current_user.uuid
86 logger.warn "User #{current_user.uuid} tried to steal lock on #{self.class.to_s} #{uuid_was} from #{is_locked_by_was}"
88 elsif !is_locked_by.nil? and is_locked_by != current_user.uuid
89 logger.warn "User #{current_user.uuid} tried to lock #{self.class.to_s} #{uuid_was} with uuid #{is_locked_by}"