-
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.
Merge pull request #102 from co-cddo/add-update-data-button
Add update data button
- Loading branch information
Showing
17 changed files
with
157 additions
and
35 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
web: bundle exec puma -C config/puma.rb | ||
release: rake db:migrate | ||
worker: rake jobs:work |
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,9 @@ | ||
class UpdateDataJob < ApplicationJob | ||
queue_as :default | ||
|
||
def perform(*_args) | ||
Rails.logger.info "Updata Data Job started" | ||
UpdateDataFromSource.call | ||
Rails.logger.info "Updata Data Job completed" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
class UpdateDataFromSource | ||
def self.call | ||
# Clear the search cache | ||
PgSearch::Document.delete_all | ||
|
||
models = [ | ||
Agreement, | ||
ControlPerson, | ||
Processor, | ||
Power, | ||
PowerAgreement, | ||
PowerControlPerson, | ||
AgreementControlPerson, | ||
AgreementProcessor, | ||
] | ||
|
||
models.each(&:populate) | ||
|
||
# Rebuild the search database | ||
# --------------------------- | ||
# Rebuilding for each class would normally do this, but the single table inheritance causes a problem | ||
# because the search record identifies each item by the table name which is always "data_tables". | ||
# This means that as you rebuild each class, the process will first remove the search records | ||
# for the classes that have previously been built. | ||
# To fix this first all the DataTable data is cleared, and then each class is rebuilt without | ||
# cleanup. | ||
PgSearch::Document.delete_by(searchable_type: "DataTable") | ||
|
||
models.each do |model| | ||
PgSearch::Multisearch.rebuild(model, clean_up: false) if model.respond_to?(:multisearchable) | ||
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,5 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment')) | ||
require 'delayed/command' | ||
Delayed::Command.new(ARGV).daemonize |
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
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,22 @@ | ||
class CreateDelayedJobs < ActiveRecord::Migration[7.0] | ||
def self.up | ||
create_table :delayed_jobs do |table| | ||
table.integer :priority, default: 0, null: false # Allows some jobs to jump to the front of the queue | ||
table.integer :attempts, default: 0, null: false # Provides for retries, but still fail eventually. | ||
table.text :handler, null: false # YAML-encoded string of the object that will do work | ||
table.text :last_error # reason for last failure (See Note below) | ||
table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future. | ||
table.datetime :locked_at # Set when a client is working on this object | ||
table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead) | ||
table.string :locked_by # Who is working on this object (if locked) | ||
table.string :queue # The name of the queue this job is in | ||
table.timestamps null: true | ||
end | ||
|
||
add_index :delayed_jobs, %i[priority run_at], name: "delayed_jobs_priority" | ||
end | ||
|
||
def self.down | ||
drop_table :delayed_jobs | ||
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 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,19 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe UpdateDataJob, type: :job do | ||
include ActiveJob::TestHelper | ||
|
||
before do | ||
ActiveJob::Base.queue_adapter = :test | ||
end | ||
|
||
describe "#perform" do | ||
it "calls update data from source process" do | ||
expect { described_class.perform_later }.to have_enqueued_job | ||
|
||
expect(UpdateDataFromSource).to receive(:call).and_return(true) | ||
|
||
perform_enqueued_jobs | ||
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