-
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.
* Creating a cron job to delete old exported files Adding whenever gem to tigerdata Automated cron job deletes exported files that are more than one week old. * rubocop 🚨 * updating cron job * deleting inventory request record a week after it is created, and after the rake task deletes the file
- Loading branch information
Showing
7 changed files
with
104 additions
and
2 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 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,21 @@ | ||
# frozen_string_literal: true | ||
class DeleteUserJob < ApplicationJob | ||
queue_as :default | ||
|
||
def perform(job_id:, user_id:) | ||
user = User.find(user_id) | ||
job = UserJob.find(job_id) | ||
job.delete | ||
|
||
mark_user_job_as_complete(job_id: job_id, user: user) | ||
end | ||
|
||
private | ||
|
||
def mark_user_job_as_complete(job_id:, user:) | ||
user_job = UserJob.create_and_link_to_user(job_id: job_id, user: user, job_title: "Deleting user job with id: #{job_id}") | ||
user_job.completed_at = Time.current.in_time_zone("America/New_York").iso8601 | ||
user_job.save! | ||
user_job.reload | ||
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,25 @@ | ||
# frozen_string_literal: true | ||
# Use this file to easily define all of your cron jobs. | ||
# | ||
# It's helpful, but not entirely necessary to understand cron before proceeding. | ||
# http://en.wikipedia.org/wiki/Cron | ||
|
||
# Example: | ||
# | ||
# set :output, "/path/to/my/cron_log.log" | ||
# | ||
# every 2.hours do | ||
# command "/usr/bin/some_great_command" | ||
# runner "MyModel.some_method" | ||
# rake "some:great:rake:task" | ||
# end | ||
# | ||
# every 4.days do | ||
# runner "AnotherModel.prune_old_records" | ||
# end | ||
|
||
# Learn more: http://github.com/javan/whenever | ||
|
||
every 1.day do | ||
rake "exports:delete_old" | ||
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,46 @@ | ||
# frozen_string_literal: true | ||
require "rails_helper" | ||
|
||
RSpec.describe DeleteUserJob, stub_mediaflux: true do | ||
let(:user) { FactoryBot.create(:user) } | ||
let(:sponsor_user) { FactoryBot.create(:project_sponsor, uid: "pul123") } | ||
let(:metadata) do | ||
{ | ||
data_sponsor: sponsor_user.uid, | ||
data_manager: sponsor_user.uid, | ||
project_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) } | ||
|
||
before do | ||
stub_request(:post, "http://mediaflux.example.com:8888/__mflux_svc__") | ||
.with(body: /<service name=\"asset.query\" session=\"test-session-token\">/) | ||
.to_return(status: 200, body: fixture_file("files/query_response.xml")) | ||
|
||
stub_request(:post, "http://mediaflux.example.com:8888/__mflux_svc__") | ||
.with(body: /<service name=\"asset.query.iterate\" session=\"test-session-token\">/) | ||
.to_return(status: 200, body: fixture_file("files/iterator_response_get_values.xml")) | ||
|
||
stub_request(:post, "http://mediaflux.example.com:8888/__mflux_svc__") | ||
.with(body: /<service name=\"asset.query.iterator.destroy\" session=\"test-session-token\">/) | ||
.to_return(status: 200, body: "") | ||
end | ||
|
||
describe "#perform_now" do | ||
it "deletes the user job that requested file inventory" do | ||
# Request inventory | ||
job = ListProjectContentsJob.perform_now(user_id: user.id, project_id: project_in_mediaflux.id) | ||
|
||
# Delete the inventory request record after a week | ||
uid = user.id.to_s | ||
described_class.perform_now(user_id: uid, job_id: job.id) | ||
expect(user.user_jobs.where("id=#{job.id}").empty?).to be_truthy | ||
end | ||
end | ||
end |