-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tigerdata Refactor: User Requests (#780)
* New Model for UserRequests * refactoring the job id on a user request to be a uuid instead of an integer * creating file inventory request and activate project requests as child classes of user request * Rename job to FileInventoryJob to match FileInventoryRequest * Delete unused rake tasks and refactor the job scheduler to run the inventory cleanup daily Co-authored-by: Bess Sadler <[email protected]> Co-authored-by: Carolyn Cole <[email protected]> Co-authored-by: Jaymee Hyppolite <[email protected]> Co-authored-by: Robert-Anthony Lee-Faison <[email protected]> Co-authored-by: James R. Griffin III <[email protected]>
- Loading branch information
1 parent
12c4376
commit e9e4eca
Showing
21 changed files
with
301 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
class FileInventoryCleanupJob < ApplicationJob | ||
queue_as :default | ||
|
||
def perform | ||
FileInventoryRequest.where(["completion_time < ?", 7.days.ago]).each do |req| | ||
File.delete(req.output_file) if File.exist?(req.output_file) | ||
req.state = UserRequest::STALE | ||
req.save | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# frozen_string_literal: true | ||
class ActivateProjectRequest < UserRequest | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# frozen_string_literal: true | ||
class FileInventoryRequest < UserRequest | ||
def output_file | ||
request_details["output_file"] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
class UserRequest < ApplicationRecord | ||
belongs_to :user | ||
belongs_to :project | ||
|
||
PENDING = "pending" | ||
COMPLETED = "completed" | ||
STALE = "stale" | ||
|
||
validates :state, inclusion: { in: [PENDING, COMPLETED, STALE] } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class CreateUserRequests < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :user_requests do |t| | ||
t.integer :user_id | ||
t.integer :project_id | ||
t.uuid :job_id | ||
t.datetime :completion_time | ||
t.string :state | ||
t.string :type | ||
t.jsonb :request_details | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,20 @@ | ||
# frozen_string_literal: true | ||
require "rails_helper" | ||
|
||
RSpec.describe ActivateProjectJob, type: :job do | ||
RSpec.describe ActivateProjectJob, connect_to_mediaflux: true, type: :job do | ||
let(:user) { FactoryBot.create(:user) } | ||
let(:sponsor_user) { FactoryBot.create(:project_sponsor, uid: "pul123") } | ||
let(:collection_id) { 1170 } | ||
let(:approved_project) { FactoryBot.create :project } | ||
let(:metadata) do | ||
{ | ||
data_sponsor: sponsor_user.uid, | ||
data_manager: sponsor_user.uid, | ||
directory: "project-123", | ||
title: "project 123", | ||
departments: ["RDSS"], | ||
description: "hello world", | ||
status: ::Project::PENDING_STATUS | ||
} | ||
end | ||
let(:project_in_mediaflux) { FactoryBot.create(:project, mediaflux_id: 8888, metadata: metadata) } | ||
let(:project_in_mediaflux) { FactoryBot.create(:project_with_doi, status: Project::APPROVED_STATUS) } | ||
|
||
before do | ||
ProjectMediaflux.create!(session_id: user.mediaflux_session, project: project_in_mediaflux) | ||
end | ||
|
||
describe "#perform_now", connect_to_mediaflux: true do | ||
it "updates the UserJob#completed_at attribute" do | ||
job = described_class.perform_now(user:, project_id: project_in_mediaflux.id) | ||
user_job = UserJob.where(job_id: job.job_id).first | ||
expect(user_job.completed_at).to_not be nil | ||
describe "#perform_now" do | ||
it "marks the state as active" do | ||
expect(project_in_mediaflux.status).to eq(Project::APPROVED_STATUS) | ||
described_class.perform_now(user: user, project_id: project_in_mediaflux.id) | ||
project_in_mediaflux.reload | ||
expect(project_in_mediaflux.status).to eq(Project::ACTIVE_STATUS) | ||
end | ||
|
||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
require "rails_helper" | ||
|
||
RSpec.describe FileInventoryCleanupJob, connect_to_mediaflux: true, type: :job do | ||
let(:user) { FactoryBot.create(:user) } | ||
let(:project_in_mediaflux) { FactoryBot.create(:project_with_doi) } | ||
let(:eight_days_ago) { Time.current.in_time_zone("America/New_York") - 8.days } | ||
|
||
before do | ||
ProjectMediaflux.create!(session_id: user.mediaflux_session, project: project_in_mediaflux) | ||
end | ||
|
||
describe "#perform_now" do | ||
it "deletes any files older than 7 days" do | ||
req = FileInventoryJob.perform_now(user_id: user.id, project_id: project_in_mediaflux.id) | ||
req.completion_time = eight_days_ago | ||
req.save | ||
|
||
expect(File.exist?(req.output_file)).to be_truthy | ||
described_class.perform_now | ||
expect(File.exist?(req.output_file)).to be_falsey | ||
end | ||
|
||
it "marks the file inventory request stale" do | ||
req = FileInventoryJob.perform_now(user_id: user.id, project_id: project_in_mediaflux.id) | ||
req.completion_time = eight_days_ago | ||
req.save | ||
|
||
expect(req.state).to eq(UserRequest::PENDING) | ||
described_class.perform_now | ||
req.reload | ||
expect(req.state).to eq(UserRequest::STALE) | ||
end | ||
end | ||
end |
Oops, something went wrong.