Skip to content

Commit

Permalink
Revert "Merge pull request opf#14992 from opf/chore/53122/replace-con…
Browse files Browse the repository at this point in the history
…currency-check-with-good-job"

This reverts commit 7b02616, reversing
changes made to 024376a.
  • Loading branch information
Eric-Guo committed Apr 1, 2024
1 parent da4e792 commit 5b0d970
Show file tree
Hide file tree
Showing 23 changed files with 117 additions and 167 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ group :development do
gem "ed25519"
gem "bcrypt_pbkdf"

gem 'debugbar'
gem "debugbar"
# Support cursor / vs code
gem "ruby-lsp", require: false
end
Expand Down
4 changes: 3 additions & 1 deletion app/contracts/settings/working_days_params_contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ def working_days_are_present
end

def unique_job
WorkPackages::ApplyWorkingDaysChangeJob.new.check_concurrency do
if GoodJob::Job
.where(finished_at: nil)
.exists?(job_class: WorkPackages::ApplyWorkingDaysChangeJob.name)
errors.add :base, :previous_working_day_changes_unprocessed
end
end
Expand Down
42 changes: 0 additions & 42 deletions app/workers/job_concurrency.rb

This file was deleted.

5 changes: 0 additions & 5 deletions app/workers/work_packages/apply_working_days_change_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,8 @@
#++

class WorkPackages::ApplyWorkingDaysChangeJob < ApplicationJob
include JobConcurrency
queue_with_priority :above_normal

good_job_control_concurrency_with(
total_limit: 1
)

def perform(user_id:, previous_working_days:, previous_non_working_days:)
user = User.find(user_id)

Expand Down
2 changes: 1 addition & 1 deletion config/initializers/debugbar.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Debugbar.configure do |config|
config.enabled = ENV["ENABLE_DEBUGBAR"] == 'true'
config.enabled = ENV["ENABLE_DEBUGBAR"] == "true"
end if Rails.env.development?
2 changes: 1 addition & 1 deletion config/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
#
workers OpenProject::Configuration.web_workers unless ENV["RAILS_ENV"] == 'development'
workers OpenProject::Configuration.web_workers unless ENV["RAILS_ENV"] == "development"

# Use the `preload_app!` method when specifying a `workers` number.
# This directive tells Puma to first boot the application and load code
Expand Down
6 changes: 3 additions & 3 deletions lib/th_annotator/apis/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_access_token
secret: ThAnnotator::Config.app_secret
}

result = ThAnnotator::Request.new.get('auth/getToken', params:)
result = ThAnnotator::Request.new.get("auth/getToken", params:)

{
token: result[:data][:accessToken],
Expand All @@ -39,7 +39,7 @@ def get_user_token(email:)
email:
}

result = ThAnnotator::Request.new.get('auth', params:)
result = ThAnnotator::Request.new.get("auth", params:)

result[:data][:token]
end
Expand All @@ -62,7 +62,7 @@ def create_document(file_name:, document_type:, view_path:)
viewPath: view_path
}

result = ThAnnotator::Request.new.post('documents', params:, data:)
result = ThAnnotator::Request.new.post("documents", params:, data:)

result[:data][:uuid]
end
Expand Down
8 changes: 4 additions & 4 deletions lib/th_annotator/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ def self.env(key)
# 域名
# @return [String]
def self.host
env('HOST')
env("HOST")
end

# 路径前缀
# @return [String]
def self.path_prefix
env('PATH_PREFIX') || ''
env("PATH_PREFIX") || ""
end

# x-app-id
# @return [String]
def self.app_id
env('APP_ID')
env("APP_ID")
end

# x-app-secret
# @return [String]
def self.app_secret
env('APP_SECRET')
env("APP_SECRET")
end
end
12 changes: 6 additions & 6 deletions lib/th_annotator/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def self.hash_with_token(hash = {}, k = :token)
def self.query2hash(query)
return {} unless query.present? && query.is_a?(String)

query.split('&').reduce({}) do |hash, item|
key, value = item.split('=')
query.split("&").reduce({}) do |hash, item|
key, value = item.split("=")
hash[key.to_sym] = URI.decode_www_form_component(value) unless value.nil?
hash
end
Expand All @@ -30,11 +30,11 @@ def self.query2hash(query)
def self.hash2query(hash)
return nil if hash.blank?

hash.to_a.reduce('') do |query, item|
hash.to_a.reduce("") do |query, item|
key, value = item
query << "&#{key}=#{URI.encode_www_form_component(value)}" unless value.nil?
query
end.sub(/^&/, '').presence
end.sub(/^&/, "").presence
end

# 生成URL
Expand All @@ -44,7 +44,7 @@ def self.hash2query(hash)
# @param fragment [String|Hash] - url#xxxxxx
# @return [String]
def self._url(host, path, query = nil, fragment = nil) # rubocop:disable Metrics/AbcSize
url = URI(Pathname.new(host).join(path.sub(/^\/+/, '')).to_s)
url = URI(Pathname.new(host).join(path.sub(/^\/+/, "")).to_s)

if query.is_a?(Hash)
hash = query2hash(url.query).merge!(query)
Expand Down Expand Up @@ -77,6 +77,6 @@ def self.url(path, params = nil, fragment = nil)
end

def self.jump_url(token:, uuid:)
_url(ThAnnotator::Config.host, request_path('auth/authorize'), { token:, documentUUID: uuid })
_url(ThAnnotator::Config.host, request_path("auth/authorize"), { token:, documentUUID: uuid })
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def callback
service.new(params).call

render json: {
message: '回调成功'
message: "回调成功"
}
rescue StandardError => e
render status: :bad_request, json: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def annotation_document

document = edoc_file.annotation_document || edoc_file.create_annotation_document

render status: 404, html: '未查询到标注文档' unless document.present?
render status: 404, html: "未查询到标注文档" unless document.present?

document.sync_members

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(attributes = {})
end

def call
raise NotImplementedError, 'You must implement the #write_to_db method in your subclass'
raise NotImplementedError, "You must implement the #write_to_db method in your subclass"
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class CreateAnnotator < Base
attr_accessor(*FIELDS)

def document=(value)
raise ArgumentError, 'Missing document' if value.blank?
raise ArgumentError, "Missing document" if value.blank?

@document = Document.new(value)
end

def annotator=(value)
raise ArgumentError, 'Missing annotator' if value.blank?
raise ArgumentError, "Missing annotator" if value.blank?

@annotator = Annotator.new(value)
end
Expand All @@ -27,7 +27,7 @@ def current_user
end

def title
'创建标注'
"创建标注"
end

def raw # rubocop:disable Metrics/AbcSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ class CreateComment < Base
attr_accessor(*FIELDS)

def document=(value)
raise ArgumentError, 'Missing document' if value.blank?
raise ArgumentError, "Missing document" if value.blank?

@document = Document.new(value)
end

def annotator=(value)
raise ArgumentError, 'Missing annotator' if value.blank?
raise ArgumentError, "Missing annotator" if value.blank?

@annotator = Annotator.new(value)
end

def comment=(value)
raise ArgumentError, 'Missing comment' if value.blank?
raise ArgumentError, "Missing comment" if value.blank?

@comment = Comment.new(value)
end
Expand All @@ -34,7 +34,7 @@ def current_user
end

def title
'创建评论'
"创建评论"
end

def raw # rubocop:disable Metrics/AbcSize
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ThAnnotationDocuments::Callbacks
class DeleteAnnotator < CreateAnnotator
def title
'删除标注'
"删除标注"
end
end
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ThAnnotationDocuments::Callbacks
class DeleteComment < CreateComment
def title
'删除评论'
"删除评论"
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def resource
@resource ||= ThAnnotationDocument.find_by!(uuid:)

unless @resource.is_a?(WorkPackageEdocFiles::ThAnnotationDocument)
raise StandardError, 'AnnotationDocument is not WorkPackageEdocFiles::ThAnnotationDocument'
raise StandardError, "AnnotationDocument is not WorkPackageEdocFiles::ThAnnotationDocument"
end

@resource
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ThAnnotationDocuments::Callbacks
class UpdateAnnotator < CreateAnnotator
def title
'更新标注'
"更新标注"
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def sync_members # rubocop:disable Metrics/AbcSize
{
name: member.principal.name,
email: member.principal.mail,
is_internal: member.principal.mail.end_with?('@thape.com.cn')
is_internal: member.principal.mail.end_with?("@thape.com.cn")
}
end

Expand Down
6 changes: 3 additions & 3 deletions modules/th_work_packages/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
OpenProject::Application.routes.draw do
scope 'th_work_packages', as: 'th_work_packages' do
scope "th_work_packages", as: "th_work_packages" do
resources :edoc_files,
controller: 'th_work_packages/edoc_files',
controller: "th_work_packages/edoc_files",
only: %i[],
as: :edoc_files do
member do
Expand All @@ -10,7 +10,7 @@
end

resources :annotation_documents,
controller: 'th_work_packages/annotation_documents',
controller: "th_work_packages/annotation_documents",
only: %i[],
as: :annotation_documents do
collection do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
class CreateThAnnotationDocuments < ActiveRecord::Migration[7.0]
def change
create_table :th_annotation_documents do |t|
t.string :uuid, null: false, default: '', index: true, comment: '文档ID'
t.string :type, null: false, default: '', index: true, comment: '文档类型'
t.integer :target_id, null: false, default: 0, index: true, comment: '目标ID'
t.json :members, null: true, default: nil, comment: '成员列表'
t.string :uuid, null: false, default: "", index: true, comment: "文档ID"
t.string :type, null: false, default: "", index: true, comment: "文档类型"
t.integer :target_id, null: false, default: 0, index: true, comment: "目标ID"
t.json :members, null: true, default: nil, comment: "成员列表"
t.timestamps
end
end
Expand Down
13 changes: 4 additions & 9 deletions spec/contracts/settings/working_days_params_contract_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

RSpec.describe Settings::WorkingDaysParamsContract do
include_context "ModelContract shared context"
shared_let(:current_user) { create(:admin) }
let(:setting) { Setting }
let(:current_user) { build_stubbed(:admin) }
let(:params) { { working_days: [1] } }
let(:contract) do
described_class.new(setting, current_user, params:)
Expand All @@ -46,16 +46,11 @@
include_examples "contract is invalid", base: :working_days_are_missing
end

context "with an ApplyWorkingDaysChangeJob already existing",
with_good_job: WorkPackages::ApplyWorkingDaysChangeJob do
context "with an ApplyWorkingDaysChangeJob already existing" do
let(:params) { { working_days: [1, 2, 3] } }

before do
WorkPackages::ApplyWorkingDaysChangeJob
.set(wait: 10.minutes) # GoodJob executes inline job without wait immediately
.perform_later(user_id: current_user.id,
previous_non_working_days: [],
previous_working_days: [1, 2, 3, 4])
ActiveJob::Base.disable_test_adapter
WorkPackages::ApplyWorkingDaysChangeJob.perform_later
end

include_examples "contract is invalid", base: :previous_working_day_changes_unprocessed
Expand Down
Loading

0 comments on commit 5b0d970

Please sign in to comment.