pg_timetable icon indicating copy to clipboard operation
pg_timetable copied to clipboard

Unable to execute python3 script as SHELL task.

Open scharri opened this issue 6 years ago • 5 comments

Describe the bug Task execution failed: {"ChainConfig":2,"ChainID":1,"TaskID":6,"TaskName":"Test","Script":"python3 /opt/test.py","Kind":"SHELL","RunUID":{"String":"1000","Valid":true},"IgnoreError":true,"Autonomous":true,"DatabaseConnection":{"String":"","Valid":false},"ConnectString":{"String":"","Valid":false},"StartedAt":"2020-08-28T11:16:16.970694537+02:00","Duration":2203}; Error: fork/exec python3 /opt/test.py: no such file or directory

file /opt/test.py exists because running python3 /opt/test.py as user with id 1000 in a terminal works great. what also work is: create a shell wrapper script 'test.sh' with content: #!/bin/sh python3 /opt/test.py and call this shell script from pg_timetable

To Reproduce create SHELL task which should run a python3 script.

Expected behavior it would be nice to be able to run python3 script with pg_timetable.

context PostgreSQL: 12.4 Python: 3.7.3 pg_timetable: 2.6 Host: Debian 10

scharri avatar Aug 28 '20 09:08 scharri

Hello. Would you please provide us with SQL for creating task for tests?

Thanks in advance

pashagolub avatar Aug 28 '20 09:08 pashagolub

Hello, here my SQL code: not working python3 script

DO $$
DECLARE
	v_task_id bigint;
	v_chain_id bigint;
	v_chain_config_id bigint;
BEGIN
	-- An example for using the SHELL task.

	-- Create the base task
	INSERT INTO timetable.base_task(name, kind, script)
	VALUES ('TEST', 'SHELL', 'python3 /opt/test.py')
	RETURNING task_id INTO v_task_id;

	-- Create the chain
	INSERT INTO timetable.task_chain(task_id, run_uid, ignore_error, autonomous)
	VALUES (v_task_id, '1000', true, true)
	RETURNING chain_id INTO v_chain_id;

	-- Create the chain execution configuration
	INSERT INTO timetable.chain_execution_config (chain_id, chain_name, live, max_instances)
	VALUES (v_chain_id, 'test chain', TRUE, 1)
	RETURNING chain_execution_config INTO v_chain_config_id;
END $$
LANGUAGE 'plpgsql';

working shell script:

DO $$
DECLARE
	v_task_id bigint;
	v_chain_id bigint;
	v_chain_config_id bigint;
BEGIN
	-- An example for using the SHELL task.

	-- Create the base task
	INSERT INTO timetable.base_task(name, kind, script)
	VALUES ('TEST2', 'SHELL', '/opt/test.sh')
	RETURNING task_id INTO v_task_id;

	-- Create the chain
	INSERT INTO timetable.task_chain(task_id, run_uid, ignore_error, autonomous)
	VALUES (v_task_id, '1000', true, true)
	RETURNING chain_id INTO v_chain_id;

	-- Create the chain execution configuration
	INSERT INTO timetable.chain_execution_config (chain_id, chain_name, live, max_instances)
	VALUES (v_chain_id, 'test2 chain', TRUE, 1)
	RETURNING chain_execution_config INTO v_chain_config_id;
END $$
LANGUAGE 'plpgsql';

scharri avatar Aug 28 '20 09:08 scharri

Thanks a lot. I see the problem here:

	-- Create the base task
	INSERT INTO timetable.base_task(name, kind, script)
	VALUES ('TEST', 'SHELL', 'python3 /opt/test.py')
	RETURNING task_id INTO v_task_id;

python3 /opt/test.py is treated as a name of the command. You should left only python and move /opt/test.py to a parameter value

pashagolub avatar Aug 28 '20 10:08 pashagolub

Thank you for reacting so fast and clarify this issue to me. I think following statement in your documentation was misleading me: under 3.1 External program | SHELL | Anything that can be called from the command line.

--> because python3 /opt/test.py can be called from command line i thought it could be insert there.

scharri avatar Aug 28 '20 10:08 scharri

@scharri thanks for approaching us with that. We found that statement unclear and are negotiating how we can remove this ambiguity.

pashagolub avatar Aug 28 '20 10:08 pashagolub