Skip to content

Commit

Permalink
Merge pull request #18542 from yrudman/fixed-finsihed-status-for-task…
Browse files Browse the repository at this point in the history
…-generationg-chargeback-foer-service

Fix: started_on and state attributes for task linked to chargeback for service
  • Loading branch information
gtanzillo authored Mar 15, 2019
2 parents c60be93 + b3814cd commit 0cae9ee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 13 additions & 3 deletions app/models/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -418,22 +418,32 @@ def chargeback_yaml
end

def queue_chargeback_report_generation(options = {})
msg = "Generating chargeback report for `#{self.class.name}` with id #{id}"
task = MiqTask.create(
:name => "Generating chargeback report with id: #{id}",
:name => msg,
:state => MiqTask::STATE_QUEUED,
:status => MiqTask::STATUS_OK,
:message => "Queueing Chargeback of #{self.class.name} with id: #{id}"
:message => "Queueing: #{msg}"
)

cb = {
:class_name => task.class.to_s,
:instance_id => task.id,
:method_name => :queue_callback,
:args => ["Finished"]
}

MiqQueue.submit_job(
:service => "reporting",
:class_name => self.class.name,
:instance_id => id,
:task_id => task.id,
:miq_task_id => task.id,
:miq_callback => cb,
:method_name => "generate_chargeback_report",
:args => options
)
_log.info("Added to queue: generate_chargeback_report for service #{name}")
_log.info("Added to queue: #{msg}")
task
end

Expand Down
2 changes: 2 additions & 0 deletions spec/models/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,8 @@
expect(args).to include(:class_name => described_class.name,
:method_name => "generate_chargeback_report",
:args => {:report_source => "Test Run"})
expect(args).to have_key(:miq_task_id)
expect(args).to have_key(:miq_callback)
end
expect(@service.queue_chargeback_report_generation(:report_source => "Test Run")).to be_kind_of(MiqTask)
end
Expand Down

0 comments on commit 0cae9ee

Please sign in to comment.