@@ -8,46 +8,80 @@ require 'bcf/flightplans'
88require 'filewatcher'
99require 'httparty'
1010
11- if ARGV . length != 3
12- warn "Usage: #{ __FILE__ } <flightplan.rb> <flightplan_version> <host>"
11+ AFP_HOST = ENV . fetch ( 'AFP_HOST' , "https://lon.activeflightplans.com" )
12+
13+ if !( ARGV . length == 1 || ARGV . length == 2 )
14+ warn "Usage: #{ __FILE__ } <flightplan.rb> [existing-key]"
1315 exit 1
1416end
1517
16- DEV_HOST = ARGV [ 2 ]
18+ FILE = ARGV [ 0 ]
1719
18- def push_change ( file )
19- # Each load will re-run the code in this ruby process.
20- # This means that we may have pre-existing state that messes things up.
21- # But for now to allow for vscode to run things we want it to be a ruby file
22- # not a shell script so this will work.
23- load ( file )
20+ def reload
21+ begin
22+ # Each load will re-run the code in this ruby process.
23+ # This means that we may have pre-existing state that messes things up.
24+ # But for now to allow for vscode to run things we want it to be a ruby file
25+ # not a shell script so this will work.
26+ load ( FILE )
27+ BCF ::FlightPlans ::FLIGHT_PLANS . last
28+ rescue
29+ puts "Failed to load..."
30+ end
31+ end
2432
25- flight_plan = BCF ::FlightPlans ::FLIGHT_PLANS . last
33+ def update ( key )
34+ flight_plan = reload
2635 HTTParty . post (
27- "http:/ /#{ DEV_HOST } /flightplans/development_live_reload_flightplan ",
36+ AFP_HOST + "/s /#{ key } /update_with_info ",
2837 headers : {
2938 "Content-Type" => "application/json"
3039 } ,
3140 body : {
32- flightplan_version : ARGV [ 1 ] ,
33- flight_plan : flight_plan
41+ delivery_session : {
42+ flight_plan : flight_plan . to_json
43+ }
3444 } . to_json
3545 )
3646
3747 puts "Pushed changes"
38- flight_plan . module_number
3948end
4049
41- module_number = push_change ( ARGV [ 0 ] )
50+ def create
51+ flight_plan = reload
52+ response = HTTParty . post (
53+ AFP_HOST + "/delivery_sessions" ,
54+ headers : {
55+ "Content-Type" => "application/json"
56+ } ,
57+ body : {
58+ delivery_session : {
59+ flight_plan : flight_plan . to_json ,
60+ start_time : Time . now . utc . iso8601
61+ }
62+ } . to_json
63+ )
64+
65+ if response . code != 201
66+ puts "Failed to create session"
67+ puts response . body
68+ exit 1
69+ end
70+
71+ puts "Created session"
72+ JSON . parse ( response . body ) [ "access_key" ]
73+ end
4274
43- test_url = URI . parse ( "http://#{ DEV_HOST } /flightplans/test_flightplan" )
44- test_url . query = URI . encode_www_form (
45- 'flightplan_delivery_testing[version]' : ARGV [ 1 ] ,
46- 'flightplan_delivery_testing[module_number]' : module_number
47- )
75+ key = if ARGV [ 1 ]
76+ # If we have been given a key push an initial update
77+ update ( ARGV [ 1 ] )
78+ ARGV [ 1 ]
79+ else
80+ create
81+ end
4882
49- puts "Test URL\n #{ test_url } "
83+ puts "Test URL: \n #{ AFP_HOST } /s/ #{ key } /delivery_consoles/new "
5084
51- Filewatcher . new ( ARGV [ 0 ] ) . watch do |changes |
52- push_change ( ARGV [ 0 ] )
85+ Filewatcher . new ( FILE ) . watch do |changes |
86+ update ( key )
5387end
0 commit comments