Merge pull request #742 from RickCarlino/in_use_stats
Add `in_use` flag to Sequences on APIpull/743/head^2
commit
c2451bbc87
|
@ -110,6 +110,10 @@ module CeleryScript
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
canonical_form = misc_fields.merge!(recurse_into_node(entry_node))
|
canonical_form = misc_fields.merge!(recurse_into_node(entry_node))
|
||||||
|
canonical_form[:in_use] = \
|
||||||
|
EdgeNode.where(kind: "sequence_id", value: sequence.id).exists? ||
|
||||||
|
RegimenItem.where(sequence_id: sequence.id).exists? ||
|
||||||
|
FarmEvent.where(executable: sequence).exists?
|
||||||
return HashWithIndifferentAccess.new(canonical_form)
|
return HashWithIndifferentAccess.new(canonical_form)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :farm_event do
|
factory :farm_event do
|
||||||
start_time { Date.yesterday - [*(1..5)].sample.days }
|
start_time { Date.yesterday - [*(1..5)].sample.days }
|
||||||
end_time { Date.today + 1.minute + ([*(1..5)].sample).days }
|
end_time { Date.today + 1.minute + ([*(1..5)].sample).days }
|
||||||
time_unit { FarmEvent::UNITS_OF_TIME.sample }
|
time_unit { FarmEvent::UNITS_OF_TIME.sample }
|
||||||
repeat { [*(1..5)].sample }
|
repeat { [*(1..5)].sample }
|
||||||
# device
|
# device
|
||||||
after(:build) do |s|
|
after(:build) do |s|
|
||||||
|
|
|
@ -5,6 +5,38 @@ describe CeleryScript::FetchCelery do
|
||||||
let(:user) { FactoryBot.create(:user) }
|
let(:user) { FactoryBot.create(:user) }
|
||||||
let(:device) { user.device }
|
let(:device) { user.device }
|
||||||
|
|
||||||
|
it "marks in_use as false when not in use" do
|
||||||
|
in_use = \
|
||||||
|
CeleryScript::FetchCelery.run!(sequence: FakeSequence.create())[:in_use]
|
||||||
|
expect(in_use).to be(false)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "marks a sequence as in_use by Regimen" do
|
||||||
|
sequence = FakeSequence.create()
|
||||||
|
ri = RegimenItem.new(time_offset: 100, sequence_id: sequence.id)
|
||||||
|
regimen = FactoryBot.create(:regimen, regimen_items: [ri])
|
||||||
|
results = CeleryScript::FetchCelery.run!(sequence: sequence)
|
||||||
|
|
||||||
|
expect(results[:in_use]).to be(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "marks a sequence as in_use by FarmEvent" do
|
||||||
|
fe = FactoryBot.create(:farm_event)
|
||||||
|
sequence = fe.executable
|
||||||
|
results = CeleryScript::FetchCelery.run!(sequence: sequence)
|
||||||
|
|
||||||
|
expect(results[:in_use]).to be(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "marks a sequence as in_use by Sequence" do
|
||||||
|
sequence = FakeSequence.create()
|
||||||
|
user = FakeSequence.create(body: [
|
||||||
|
{ kind: "execute", args: { sequence_id: sequence.id } }
|
||||||
|
])
|
||||||
|
results = CeleryScript::FetchCelery.run!(sequence: sequence)
|
||||||
|
expect(results[:in_use]).to be(true)
|
||||||
|
end
|
||||||
|
|
||||||
__NOTHING______ = "nothing"
|
__NOTHING______ = "nothing"
|
||||||
|
|
||||||
it "Makes JSON that is identical to the legacy implementation - part 1" do
|
it "Makes JSON that is identical to the legacy implementation - part 1" do
|
||||||
|
|
|
@ -57,6 +57,7 @@ export interface Sequence extends CeleryScriptSequence {
|
||||||
id?: number;
|
id?: number;
|
||||||
color: Color;
|
color: Color;
|
||||||
name: string;
|
name: string;
|
||||||
|
in_use?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SequenceReducerState {
|
export interface SequenceReducerState {
|
||||||
|
|
Loading…
Reference in New Issue