On pátek 16. prosince 2016 16:28:47 CET Daniel Kuffner wrote:
> Hi All,
> 
> I was looking for a simple example of how to use locks of foreman-tasks
> (dynflow). I can see that Actions::EntryAction mixes in the
> Actions::Helpers::Lock but for me it is not clear how to use it.
> 
> regards,
> Daniel

Hello,

there are two types of locks - exclusive (blocking other tasks to lock the 
same resource) and non-exclusive also called links. To automatically create 
link to some object, you only define related_resource method in your task

       def related_resources
         [ ::Host.first ]
       end

As you can see, it should return array of linked objects, first host in this 
case.

To create a lock you need to first defined what locks are available for a 
given task, e.g.

       # names of locks that can be locked
       def available_locks
         [ :read, :write ]
       end

When the task has this defined you can lock resources in planning like this

       # locking only in plan phase
       def plan(params)
         lock!(::FactValue.first, :read)
         # exclusive_lock!(::Host.last) # locks all available locks on a given 
resource
         link!(::FactValue.last) # this would add link lock
         plan_self :params => params
       end
       # exclusive_lock! and lock! creates the same kind of lock, 
exclusive_lock! just locks all available locks

I'm in the middle of writing the manual for the foreman-tasks plugin. When I 
finish user guide, I'll send a PR so others can contribute. I also plan to put 
together developer guide which would cover this.

Hope this helps

--
Marek

-- 
You received this message because you are subscribed to the Google Groups 
"foreman-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to foreman-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to