T
T
Tesla_Rails2015-09-24 14:50:29
Ruby on Rails
Tesla_Rails, 2015-09-24 14:50:29

How to write a Worker to change status?

There is an Order model, which has a "status" field of type string.
You need to write a worker that, after a certain time, will change the status of each order to the next one, up to the last one. Statuses, I think, should be placed in the constant STATUSES = %w(in_progress approved shiped received). Well, to make it work on Heroku.
What is the best way to implement this? Previously, I did not have to write workers, so I ask for help from you. Thanks in advance

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Ivanov, 2015-09-24
@Tesla_Rails

Use Sidekiq

B
Biggless, 2015-10-14
@Biggless

And enum instead of constants.
If additional logic is required when changing statuses - a state machine. For example, aasm .
If the shift needs to be done at a certain time (for example, an hour after creation) - you can get by with one sidekiq. If every hour or at midnight - clockwork will help .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question