def do_cancel (msg)
flavour = msg['flavour']
return if h.state == 'cancelling' && flavour != 'kill'
return if h.state == 'failed' && flavour == 'timeout'
@msg = Ruote.fulldup(msg)
h.state = case flavour
when 'kill' then 'dying'
when 'timeout' then 'timing_out'
else 'cancelling'
end
h.applied_workitem['fields']['__timed_out__'] = [
h.fei, Ruote.now_to_utc_s
] if h.state == 'timing_out'
if h.state == 'cancelling'
if t = msg['on_cancel']
h.on_cancel = t
elsif hra = msg['re_apply']
hra = {} if hra == true
h.on_cancel = hra['tree'] || tree
if fs = hra['fields']
h.applied_workitem['fields'] = fs
end
if mfs = hra['merge_in_fields']
h.applied_workitem['fields'].merge!(mfs)
end
end
end
cancel(flavour)
end