Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cancel #463

Merged
merged 6 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions server/app/jobs/dj_jobs/run_simulate_data_point.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,17 @@ class RunSimulateDataPoint
require 'json'

def initialize(data_point_id, options = {})

@options = options

@data_point = DataPoint.find(data_point_id)
@data_point.status = :queued
@data_point.run_queue_time = Time.now
@options = options
@intialize_worker_errs = []

# this is also run from resque job, which leverages perform code below.
# only queue data_point on initialize for delayed_jobs
@data_point.set_queued_state if Rails.application.config.job_manager == :delayed_job

end


def perform
# Create the analysis, simulation, and run directory
FileUtils.mkdir_p analysis_dir unless Dir.exist? analysis_dir
Expand Down
5 changes: 5 additions & 0 deletions server/app/jobs/resque_jobs/run_simulate_data_point.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ module ResqueJobs
class RunSimulateDataPoint
@queue = :simulations

def self.after_enqueue(data_point_id, options = {})
d = DataPoint.find(data_point_id)
d.set_queued_state
end

def self.perform(data_point_id, options = {})
job = DjJobs::RunSimulateDataPoint.new(data_point_id, options)
job.perform
Expand Down
1 change: 0 additions & 1 deletion server/app/models/analysis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ def stop_analysis
logger.info('attempting to stop analysis')

self.run_flag = false
# The ensure block will clean up the jobs and save the statuses

jobs.each do |j|
unless j.status == 'completed'
Expand Down
10 changes: 8 additions & 2 deletions server/app/models/data_point.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,20 @@ def set_complete_state
end

def set_canceled_state
self.destroy_background_job # Remove the datapoint from the delayed jobs queue
self.destroy_background_job # destroy queued job
self.run_start_time ||= Time.now
self.run_end_time = Time.now
self.status = :completed
self.status_message = 'datapoint canceled'
save!
end

def set_queued_state
self.status = :queued
self.run_queue_time = Time.now
save!
end

protected

def verify_uuid
Expand All @@ -160,7 +166,7 @@ def destroy_background_job
end
elsif Rails.application.config.job_manager == :resque
if job_id
Resque::Job.destroy(:simulations, 'ResqueJobs::RunSimulateDataPointResque', job_id)
Resque::Job.destroy(:simulations, 'ResqueJobs::RunSimulateDataPoint', job_id)
end
else
raise 'Rails.application.config.job_manager must be set to :resque or :delayed_job'
Expand Down