irods / irods_capability_automated_ingest

Other
12 stars 15 forks source link

Wrong exit code with --synchronous option #177

Closed JonathanMELIUS closed 1 year ago

JonathanMELIUS commented 2 years ago

Bug Report

iRODS Version, OS and Version

iRODS: 4.2.6 Ubuntu 18.04.4 LTS Python virtual environment: 3.10.5 Redis server 4.0.9 Celery 5.2.7 iRODS Automated Ingest Framework 0.4.0

What did you try to do?

I tried to get the exit code after running a ingest job with the synchronous option activated

Expected behavior

I expected the exit code to be 0 when the job was successfully executed. This is important for us to correctly incorporate the iRODS Automated Ingest Framework into our existing ingest workflow.

Observed behavior (including steps to reproduce, if applicable)

I get a 255 exit code

(rodssync) irods@ires:/tmp$ ls -l /tmp/source_directory/
total 10540
-rw-rw-r-- 1 irods irods 2157087 Aug  2 14:44 img0.jpg
-rw-rw-r-- 1 irods irods 2157087 Aug  2 14:44 img1.jpg
-rw-rw-r-- 1 irods irods 2157087 Aug  2 14:44 img2.jpg
-rw-rw-r-- 1 irods irods 2157087 Aug  2 14:44 img3.jpg
-rw-rw-r-- 1 irods irods 2157087 Aug  2 14:44 img4.jpg
(rodssync) irods@ires:/tmp$ python -m irods_capability_automated_ingest.irods_sync start /tmp/source_directory/ /nlmumc/home/rods/put_coll --synchronous
(rodssync) irods@ires:/tmp$ echo $?
255
(rodssync) irods@ires:/tmp$ ils -l /nlmumc/home/rods/put_coll
/nlmumc/home/rods/put_coll:
  rods              0 rootResc;demoResc      2157087 2022-08-02.14:44 & img0.jpg
  rods              0 rootResc;demoResc      2157087 2022-08-02.14:44 & img1.jpg
  rods              0 rootResc;demoResc      2157087 2022-08-02.14:44 & img2.jpg
  rods              0 rootResc;demoResc      2157087 2022-08-02.14:44 & img3.jpg
  rods              0 rootResc;demoResc      2157087 2022-08-02.14:44 & img4.jpg

The issue seems to come from this check:

    failures = job.failures_handle().get_value()
    if failures != 0:
        return -1
    else:
        return 0

https://github.com/irods/irods_capability_automated_ingest/blob/c60e2cc94f3ccb182c88db2c5bf7dff7b344ed9a/irods_capability_automated_ingest/sync_actions.py#L92

With the synchronous option activated, failures in this case is null|None.

A simple patch would bring the desired outcome: Patch:

    failures = job.failures_handle().get_value()
#    print(f"failures: {failures}")
    if failures is not None and failures != 0:
        return -1
    else:
        return 0

New result:

(rodssync) irods@ires:/tmp$ python -m irods_capability_automated_ingest.irods_sync start /tmp/source_directory/ /nlmumc/home/rods/reg_coll4 --synchronous
failures: None
(rodssync) irods@ires:/tmp$ echo $?
0
trel commented 2 years ago

We'll reproduce - thanks!

trel commented 2 years ago

Reproduced!

Would you like to submit a pull request with your changes - so that you get credit in the commit log?

JonathanMELIUS commented 2 years ago

Nice, I will submit a pull request right away.

rmoreas commented 1 year ago

It would be nice that new patch releases are created for such fixes. I've been troubleshooting a long time on my code to find out why I always got the wrong exit code, not knowing that there was a unreleased fix.

I know, it's me own fault that I was looking at the main branch instead of the tagged version, but it also pinpoints the lack of frequent releases. Can we do something to improve release management?

trel commented 1 year ago

Hi @rmoreas - we'll get 0.4.1 released today.

trel commented 1 year ago

Not quite as promised - but 0.4.1 is now out. Please open a new issue if you find anything.

rmoreas commented 1 year ago

Thanks @trel