Menu

Simultaneous Locks

2016-05-26
2016-05-30
  • Jason Morin

    Jason Morin - 2016-05-26

    Good Day,

    Thank you for the excellent software. I am finding it very useful and thus far is the superior means of ensuring my processes run one at a time.

    I have two scripts and each script contains a command I want to limit to one instance. Each process runs 4x/hour offset by 10 minutes by cron:

    script 1: 0,15,30,45
    script 2: 10,25,40,55

    Script 1 can often take more than 10 minutes to complete. This means that script 1 could be running while script 2 begins. This isn't a problem, script 1 grabs a bunch of data and script 2 processes it. I would like to lock script 1 so that a single connection to a remote server exists to grab new data. Script 2 needs to be locked because it writes data to a database and I don't want duplicate entries etc. I currently have flom running in script 2. Is it possible to ahve script 1 contain a flom as we well, permitting script 2 to run (the flom would block an additional script 1 from running not block script 2).

    Many Thanks.

     
  • Jason Morin

    Jason Morin - 2016-05-27

    EDIT: Perhaps Case #2 is exactly what I described and as an extension permits locks on unlimited synchronized processes.

     
  • Christian Ferrari

    Dear Jason,
    flom commands synchronize using resources.
    If you don't specify the resource name (command line option "-r" or "--resource-name", config key "[Resource]/Name"), flom command will use a default resource: it's name is

    _DEFAULT
    

    but you will never see it, it's internal stuff.
    If you need to synchronize indipendent processes, you can use distinct resources, as you have already figured out from Use Case #2.

     
  • Jason Morin

    Jason Morin - 2016-05-29

    Thank you, Christian, for responding. I had in my cron: flom --resource-timeout=0 command args
    so if I were to flom --resoure-timeout=0 --resource-name -- command args
    this should work?

     
  • Christian Ferrari

    Dear Jason,
    the option --resource-name needs an argument, the name of the resource.
    You should use something like:

    flom --resource-timeout=0 --resource-name=R1 -- command1 args
    

    for all the commands that you want to synchronize on the first resource (R1).

    You should use a second one:

    flom --resource-timeout=0 --resource-name=R2 -- command2 args
    

    for all the commands that you want to synchronize on the second resource (R2).

    In the above example, command1 and command2 can run at the same time, but flom will avoid a parallel execution of two or more command1 and it will avoid a parallel execution of two or more command2.

     
  • Jason Morin

    Jason Morin - 2016-05-30

    Brilliant! Thank you very much, Christian. It was the "=R1" that I didn't figure out. It works beautifully.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.