https://prefect.io logo
Title
r

Richard Hughes

09/08/2020, 7:47 PM
Hi All, I am looking for how to run a flow using the prefect
version_group_id
Where is the documentation for this?
j

Jenny

09/08/2020, 7:51 PM
Hi @Richard Hughes - how do you want to run the flow? You could use the
create_flow_run
mutation in the Interactive API - the docs are right there in the Interactive API page of the UI. If you want to do something different, please let us know.
r

Richard Hughes

09/08/2020, 7:52 PM
I want to do this from a console
j

Jenny

09/08/2020, 7:55 PM
r

Richard Hughes

09/08/2020, 9:27 PM
@Jenny how do put my parameters into this call? example:
prefect run cloud --version_group_id "PROD.System.SQLFileExecution" --project "PROD" --paramters SQLFileName="F:\\Shares\\System\\Script.sql"
I found this: https://docs.prefect.io/api/latest/cli/run.html
prefect run cloud --version_group_id "PROD.System.SQLFileExecution" --project "PROD" --parameters-string {"SQLFileName": "F:\\Shares\\System\\Script.sql"}
does this work for
-ps
?
j

Jenny

09/08/2020, 10:13 PM
Not quite sure I understand the question. Do you mean can -ps be used instead of --parameters-string? You can also use -h or --help to get a list of those commands.
r

Richard Hughes

09/10/2020, 10:41 PM
@Jenny, I am still having trouble passing the json parameters into the
prefect run cloud
. I've tried both
--parameter-string
and
--parameter-file
I am using powershell console in my case, I am not sure if this is causing the issue. Example:
@{SQLFileName="F:\Shares\Snowflake\System\AccessControl.sql"} | ConvertTo-Json -compress > .\parameters.json
Get-Content .\parameters.json
prefect auth login -t $env:prefect_token
prefect run cloud --name "System.SQLFileExecution" --project "PROD" --parameters-file parameters.json
Traceback (most recent call last):
  File "c:\python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Python37\Scripts\prefect.exe\__main__.py", line 7, in <module>
  File "c:\python37\lib\site-packages\click\core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "c:\python37\lib\site-packages\click\core.py", line 782, in main
    rv = self.invoke(ctx)
  File "c:\python37\lib\site-packages\click\core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "c:\python37\lib\site-packages\click\core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "c:\python37\lib\site-packages\click\core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\python37\lib\site-packages\click\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "c:\python37\lib\site-packages\prefect\cli\run.py", line 217, in cloud
    no_url=no_url,
  File "c:\python37\lib\site-packages\prefect\cli\run.py", line 369, in _run_flow
    file_params = json.load(params_file)
  File "c:\python37\lib\json\__init__.py", line 296, in load
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
  File "c:\python37\lib\json\__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "c:\python37\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "c:\python37\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
j

Jenny

09/10/2020, 11:07 PM
Ah - I'm not an expert on the way the CLI handles JSON but for graphql mutations the JSON can be a little tricky and I suspect it may be the same here. You might need to add "\ as in the graphql docs here: https://docs.prefect.io/orchestration/concepts/flow_runs.html#graphql But let me double check that for you.
r

Richard Hughes

09/10/2020, 11:17 PM
@Jenny let me escape those double quotes and try again, fingers crossed
j

Jenny

09/10/2020, 11:19 PM
I just tried it myself and it went through. So for example {"c":3} would need to be "{\"c\":3}". We'll need to update that in the help section of the CLI as I see it suggests parameters without that escape.
Can you let me know if it works for you too?
r

Richard Hughes

09/10/2020, 11:24 PM
Here is the winning combo:
prefect run cloud --name "System.SQLFileExecution" --project "PROD" --parameters-string '{\"SQLFileName\":\"F:\\Shares\\System\\Script.sql\"}'
, now my fingers are crossed again this will run in azure devops w/ remote powershell cmdlet
j

Jenny

09/10/2020, 11:26 PM
Great! Thank you.
I've added an issue for this here. Feel free to add any extra info if you feel it's useful.
👍 1
r

Richard Hughes

09/11/2020, 12:35 AM
success! thanks for you help on this on
👍 1