+
+ def update_modified_by_fields
+ if self.cancelled_at_changed?
+ # Ensure cancelled_at cannot be set to arbitrary non-now times,
+ # or changed once it is set.
+ if self.cancelled_at and not self.cancelled_at_was
+ self.cancelled_at = Time.now
+ self.cancelled_by_user_uuid = current_user.uuid
+ self.cancelled_by_client_uuid = current_api_client.uuid
+ @need_crunch_dispatch_trigger = true
+ else
+ self.cancelled_at = self.cancelled_at_was
+ self.cancelled_by_user_uuid = self.cancelled_by_user_uuid_was
+ self.cancelled_by_client_uuid = self.cancelled_by_client_uuid_was
+ end
+ end
+ super
+ end
+
+ def trigger_crunch_dispatch_if_cancelled
+ if @need_crunch_dispatch_trigger
+ File.open(Rails.configuration.crunch_refresh_trigger, 'wb') do
+ # That's all, just create/touch a file for crunch-job to see.
+ end
+ end
+ end
+
+ def log_buffer
+ begin
+ @@redis ||= Redis.new(:timeout => 0)
+ if @@redis.exists uuid
+ @@redis.getrange(uuid, 0 - 2**10, -1)
+ end
+ rescue Redis::CannotConnectError
+ return '(not available)'
+ end
+ end