complete the action to launch a prepared task
4 files changed, 50 insertions(+), 1 deletions(-)

M elm/src/Main.elm
M elm/src/Type.elm
M rework_ui/blueprint.py
M tests/test_rui.py
M elm/src/Main.elm +18 -0
@@ 449,6 449,11 @@ update msg model =
             nocmd <| log model ERROR err
 
         LaunchNow sid ->
+            ( model
+            , launchnow model sid
+            )
+
+        InstantLaunchFromSchedule _ ->
             nocmd model
 
         DeleteSched sid ->

          
@@ 573,6 578,19 @@ getlaunchers model =
     }
 
 
+launchnow model sid =
+    Http.request
+    { url = UB.crossOrigin model.baseurl
+          [ "launch-scheduled/" ++ String.fromInt sid ] [ ]
+    , method = "PUT"
+    , headers = []
+    , body = Http.emptyBody
+    , expect = Http.expectWhatever InstantLaunchFromSchedule
+    , timeout = Nothing
+    , tracker = Nothing
+    }
+
+
 refreshCmd : Model -> TabsLayout -> Cmd Msg
 refreshCmd model tab =
     let

          
M elm/src/Type.elm +1 -0
@@ 237,6 237,7 @@ type Msg
     | PreScheduleFailed String
     | PreScheduleOk String
     | LaunchNow Int
+    | InstantLaunchFromSchedule (Result Http.Error ())
     -- events
     | HandleKeyboardEvent KeyboardEvent
     | SelectDisplayLevel Level

          
M rework_ui/blueprint.py +24 -0
@@ 8,6 8,7 @@ import tzlocal
 from flask import (
     abort,
     Blueprint,
+    jsonify,
     make_response,
     request,
     render_template,

          
@@ 243,6 244,29 @@ def reworkui(engine,
         )
         return json.dumps(newtask.tid)
 
+    @bp.route('/launch-scheduled/<int:sid>', methods=['PUT'])
+    def launch_scheduled(sid):
+        if not has_permission('launch'):
+            return json.dumps(0)
+
+        q = select(
+            'op.name', 's.domain', 's.inputdata', 's.host', 's.metadata',
+        ).table('rework.sched as s', 'rework.operation as op'
+        ).where('s.operation = op.id'
+        ).where('s.id = %(sid)s', sid=sid)
+        sched = q.do(engine).fetchone()
+
+        t = api.schedule(
+            engine,
+            sched[0],
+            rawinputdata=sched[2] if sched[2] else None,
+            hostid=sched[3],
+            domain=sched[1],
+            metadata=sched[4]
+        )
+
+        return jsonify({'tid': t.tid})
+
     @bp.route('/job_input/<jobid>')
     def job_input(jobid):
         if not has_permission('read'):

          
M tests/test_rui.py +7 -1
@@ 280,7 280,7 @@ def test_schedulers(engine, client):
         rule='1 2 * * * *'
     )
 
-    api.prepare(
+    sid = api.prepare(
         engine,
         'with_inputs',
         rule='0 9 * * * *',

          
@@ 302,6 302,12 @@ def test_schedulers(engine, client):
         ]
     ]
 
+    res = client.put(f'/launch-scheduled/{sid}')
+    assert 'tid' in res.json
+    tid = res.json['tid']
+    task = Task.byid(engine, tid)
+    assert task.state == 'queued'
+
 
 def test_read_io(engine, client):
     res = client.put(