Recommend this page to a friend! |
![]() |
Info | Documentation | ![]() |
![]() |
![]() |
Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not enough user ratings | Total: 112 | All time: 9,623 This week: 36![]() |
Version | License | PHP version | Categories | |||
immutable-state-stat 1.0 | MIT/X Consortium ... | 5.6 | PHP 5, Databases, Files and Folders, L..., D... |
Description | Author | |||
This package can manage the status of queue using immutable data structures. Innovation Award
|
|
The best way to install this module is with composer. You could also just clone this down into your modules path if you so desire/require.
require: [
...
"jackdpeterson/immutable-state-status-tracker": "dev-master"
...
]
In config/application.config.php:
return array('modules' =>
array(
...
'ImmutableStateStatusTracker'
...
)
);
Assume we need to perform bulk downloading and processing of images. Only after theses tasks are completed should our broader process move on to the next phase (in this case, notify the user).
processBigImageCollectionJob (which is comprised of download Images, and resize the collection). The second subtask is to notify the user after ALL images have been downloaded and processed.
Task #1 - Download a collection of images (say 10,000 images divided into 100 image processing blocks [100 components related to the downloadImageCollection task])
Task #2 - resize collection of 100 images at a time [100 components related to the processImage task].
To accomplish #1 is fairly straightforward ... we'll create one job with the 200 total components (100 for downloading 100 images per job, and 100 for processing 100 images in a single batch operation).
To accomplish #2 we would have some kind of process that scans the jobs submitted for their state. upon completion or failure an action the job from the watchlist could be popped off the list and some action taken.
protected $statusTracker;
public function __construct(StatusTrackerServiceInterface $statusTracker) {
$this->statusTracker = $statusTracker;
}
...
public function execute() {
$jobToTrack = $this->statusTracker->createJob(array(
'download_images_[0-9]', // saving space here, but this would literally be 10 entries (one for each respective job)
'resize_and_upload_images_[0-99]', // same story -- except we have 100 entries here (let's assume higher computational complexity)
'notification_email'
));
// divide the list out and submit the 100 downloadAndStoreImageCollection job and pass in the identifier for which task id this is
// submit a status tracking job <-- recurring magic happens here ;-)
$newJob->setContents(array(
'status_job_id' => $job->getJobId(),
'shard_number' => 2,
'collection_of_images_pointer' => 'somethingUseful'
));
}
...
protected $statusTracker;
public function __construct(StatusTrackerServiceInterface $statusTracker) {
$this->statusTracker = $statusTracker;
}
public function execute() {
$expectedParams = array(
'collection_of_images_list_pointer' => 'someObjectReference (e.g., REDIS key)',
'shard_id' => 35, // this is the identifier that will be used (effectively the shard key).
'status_job_id' => 'something provided by the previous step'
);
// ADD IN A STATUS EVENT!!
$event = $this->statusTracker->addStatusEvent($job->getJobId(), $job->getComponents()[0], StatusEvent::STATUS_IN_PROGRESS, 'Started downloading collection:' .
$inputParams['shard_id']);
}
This last step is of course up to the implementor; however, in general one would call calculateJob() and work with the last events and the overall status to decide on the most appropriate course of action.
public function execute() {
// adding this because the queue may be very quick and we don't want to introduce lots of repeated jobs for no reason.
sleep(120);
$status = $this->statusTracker->calculateJob()
// Push a new status check event into the queue (recursively run this until it appropriately exits) DANGER!!!.
if ($status->getOverallStatus() == CalculatedJobStatus::STATUS_IN_PROGRESS) {
// maybe check that all downloads are done processing
// --> Do something here (e.g., fire off the notification task)!
}
if ($status->getOverallStatus() == CalculatedJobStatus::STATUS_COMPLETED) {
// fire event and then remove the job?
}
if ($status->getOverallStatus() == CalculatedJobStatus::STATUS_FAILED) {
// maybe send this to a special logging facility to notify devs and collect as much data as possible?
}
}
Calling statusTracker->calculateJob() returns an instance of Entity\Calculatedstatus or throws exceptions.
Calculated status contains a few variables: * (string) overallStatus, * (Entity\Job) job, * (array __componentName => Entity\StatusEvent__) This is determined by the value of the createdAt value (highest = last).
Job is the instance of Entity\Job
https://github.com/juriansluiman/SlmQueue - SlmQueue Module
This is a known issue. The precision of status events are to the second level (1/60th of a minute). If this is a frequent occurance in your code then adding [code below] prior submitting the status event should resolve this problem out until a better solution thought up.
sleep(2);
If you're still having issues, look at your syslog as the factory sends information to there including the stack trace for further diagnostic information.
On Ubuntu run:
$ sudo tail -f /var/log/syslog
Submit an issue and/or Pull request!
![]() |
File | Role | Description | ||
---|---|---|---|---|
![]() |
||||
![]() |
||||
![]() |
||||
![]() |
||||
![]() |
||||
![]() |
Data | Auxiliary data | ||
![]() |
Data | Auxiliary data | ||
![]() |
Data | Auxiliary data | ||
![]() |
Aux. | Class source | ||
![]() |
Aux. | Class source | ||
![]() |
Aux. | Class source | ||
![]() |
Data | Auxiliary data | ||
![]() |
Lic. | License text | ||
![]() |
Class | Class source | ||
![]() |
Data | Auxiliary data | ||
![]() |
Doc. | Auxiliary data |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
![]() |
![]() | immutable-state-stat-2016-08-15.zip 38KB |
![]() | immutable-state-stat-2016-08-15.tar.gz 23KB |
![]() | Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.