librelist archives

« back to archive

Clean up Entity State Before Retry

Clean up Entity State Before Retry

From:
Karl Falconer
Date:
2014-03-26 @ 12:57
I have an entity that uses a statemachine to progress through a workflow.

I am wondering if there is a way to reset the state of the entity if there
is a failure during the job execution.

def perform(entity)
  # Precondition check
  raise "Wrong State" unless entity.scheduled?

  # Update state to processing
  entity.processing

  # ... do work

  # Update state to complete
  entity.complete
end


So if the job fails after the state transition, during the retry an
exception would be raised. Is there a way to know if the job is being
retried, reset the state then begin the work?

Thanks

Re: [sidekiq] Clean up Entity State Before Retry

From:
Mike Perham
Date:
2014-03-26 @ 13:49
Use a db transaction?

> On Mar 26, 2014, at 5:57, Karl Falconer <karl@getdropstream.com> wrote:
> 
> I have an entity that uses a statemachine to progress through a workflow.
> 
> I am wondering if there is a way to reset the state of the entity if 
there is a failure during the job execution.
> 
> 
> def perform(entity)
>   # Precondition check
>   raise "Wrong State" unless entity.scheduled?
> 
>   # Update state to processing
>   entity.processing
> 
>   # ... do work
> 
>   # Update state to complete
>   entity.complete
> end
> 
> So if the job fails after the state transition, during the retry an 
exception would be raised. Is there a way to know if the job is being 
retried, reset the state then begin the work?
> 
> Thanks
> 

Re: [sidekiq] Clean up Entity State Before Retry

From:
Karl Falconer
Date:
2014-03-26 @ 15:11
Wouldn't the transaction negate the purpose of having the state transitions?

So the state would move from scheduled -> complete, if there was no error
during the job execution. If there was an error, the state would simply
stay in the scheduled state.




On Wed, Mar 26, 2014 at 9:49 AM, Mike Perham <mperham@gmail.com> wrote:

> Use a db transaction?
>
> On Mar 26, 2014, at 5:57, Karl Falconer <karl@getdropstream.com> wrote:
>
> I have an entity that uses a statemachine to progress through a workflow.
>
> I am wondering if there is a way to reset the state of the entity if there
> is a failure during the job execution.
>
> def perform(entity)
>   # Precondition check
>   raise "Wrong State" unless entity.scheduled?
>
>   # Update state to processing
>   entity.processing
>
>   # ... do work
>
>   # Update state to complete
>   entity.complete
> end
>
>
> So if the job fails after the state transition, during the retry an
> exception would be raised. Is there a way to know if the job is being
> retried, reset the state then begin the work?
>
> Thanks
>
>


-- 
*Karl Falconer*
Founder, Dropstream
Email: karl@getdropstream.com
Twitter: http://twitter.com/getdropstream
Website: http://getdropstream.com
Phone: 540-808-6436

Re: [sidekiq] Clean up Entity State Before Retry

From:
Chew Manfoo
Date:
2014-03-26 @ 15:14
I'm using workflow for this - within the worker I execute some sort of
action (like a script with a valid exit code) and I exit the worker (and
transition to the new state) cleanly with an exit code of 0 but I respawn
the worker with an exit code of non-zero.


On Wed, Mar 26, 2014 at 10:11 AM, Karl Falconer <karl@getdropstream.com>wrote:

> Wouldn't the transaction negate the purpose of having the state
> transitions?
>
> So the state would move from scheduled -> complete, if there was no error
> during the job execution. If there was an error, the state would simply
> stay in the scheduled state.
>
>
>
>
> On Wed, Mar 26, 2014 at 9:49 AM, Mike Perham <mperham@gmail.com> wrote:
>
>> Use a db transaction?
>>
>> On Mar 26, 2014, at 5:57, Karl Falconer <karl@getdropstream.com> wrote:
>>
>> I have an entity that uses a statemachine to progress through a workflow.
>>
>> I am wondering if there is a way to reset the state of the entity if
>> there is a failure during the job execution.
>>
>>
>> def perform(entity)
>>   # Precondition check
>>   raise "Wrong State" unless entity.scheduled?
>>
>>   # Update state to processing
>>   entity.processing
>>
>>   # ... do work
>>
>>   # Update state to complete
>>   entity.complete
>> end
>>
>>
>> So if the job fails after the state transition, during the retry an
>> exception would be raised. Is there a way to know if the job is being
>> retried, reset the state then begin the work?
>>
>> Thanks
>>
>>
>
>
> --
> *Karl Falconer*
> Founder, Dropstream
> Email: karl@getdropstream.com
> Twitter: http://twitter.com/getdropstream
> Website: http://getdropstream.com
> Phone: 540-808-6436
>

Re: [sidekiq] Clean up Entity State Before Retry

From:
Mike Perham
Date:
2014-03-26 @ 15:18
We use a different worker for each state change plus db transactions.  In 
your case there's no point to the state machine if you're going to make 
the job atomic with a transaction. 

> On Mar 26, 2014, at 8:11, Karl Falconer <karl@getdropstream.com> wrote:
> 
> Wouldn't the transaction negate the purpose of having the state transitions?
> 
> So the state would move from scheduled -> complete, if there was no 
error during the job execution. If there was an error, the state would 
simply stay in the scheduled state.
> 
> 
> 
> 
>> On Wed, Mar 26, 2014 at 9:49 AM, Mike Perham <mperham@gmail.com> wrote:
>> Use a db transaction?
>> 
>>> On Mar 26, 2014, at 5:57, Karl Falconer <karl@getdropstream.com> wrote:
>>> 
>>> I have an entity that uses a statemachine to progress through a workflow.
>>> 
>>> I am wondering if there is a way to reset the state of the entity if 
there is a failure during the job execution.
>>> 
>>> 
>>> def perform(entity)
>>>   # Precondition check
>>>   raise "Wrong State" unless entity.scheduled?
>>> 
>>>   # Update state to processing
>>>   entity.processing
>>> 
>>>   # ... do work
>>> 
>>>   # Update state to complete
>>>   entity.complete
>>> end
>>> 
>>> So if the job fails after the state transition, during the retry an 
exception would be raised. Is there a way to know if the job is being 
retried, reset the state then begin the work?
>>> 
>>> Thanks
> 
> 
> 
> -- 
> Karl Falconer
> Founder, Dropstream
> Email: karl@getdropstream.com
> Twitter: http://twitter.com/getdropstream
> Website: http://getdropstream.com
> Phone: 540-808-6436