Here's the situation:
I have a Laravel 4.2 application that retrieves (from a third-party API) an asset. This is a long-lived asset (it changes only once every 12-24 hours) and is time-consuming (large image file). I do asset caching, so the impact was more or less minimized, but it still happens that the first person who enters my application in the morning has to wait while the application downloads this asset for the first time.
I created a task that will stand in line and will be executed every eight hours. This should ensure that the asset in the cache is always fresh. It works by restarting the task eight hours after its launch.
The problem is this: I am going to deploy this system of production tasks, and I am not sure how to start this work for the first time.
Ideally, I would like to have an administration option where I have a button that says “Click here to submit the task,” but I would like to make it as reliable as possible and prevent people (I'm not the only administrator) from submitting tasks several times. To do this, however, the application must check and see if the task is already in the queue. I cannot find a way to make this implementation-independent (I use redis, but this may change in the future).
Another option is to add a command artisanto start the initial process. That way, I could deploy the application, run the artisan command and forget about it.
, , :