Skip to content

Instantly share code, notes, and snippets.

@clouddueling
Last active April 10, 2016 14:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save clouddueling/5239153 to your computer and use it in GitHub Desktop.
Save clouddueling/5239153 to your computer and use it in GitHub Desktop.
laravel long pulling only allows 1 pull to be going at any time by utilizing the file system.
var Checkin = (function(window, document, undefined) {
var s = {
contact: {}
},
showing = false;
function init() {
bindVerify();
bindDeny();
waitForMsg();
}
function bindDeny() {
c.on('click', '[data-deny-contact]', function(){
$.get('/focus/contact/deny', s.contact, function(){
$('.verify-contact').slideUp('medium');
toastr.success("Contact denied check-in.");
});
});
}
function bindVerify() {
c.on('click', '[data-verify-contact]', function(){
$.get('/focus/contact/verify', s.contact, function(){
$('.verify-contact').slideUp('medium');
toastr.success("Contact verified for check-in.");
});
});
}
function waitForMsg() {
$.get('/focus/contact/verify', function(data){
var view = viewVerify(data);
s.contact = data;
$('.verify-contact').show(0).html(view);
setTimeout(function(){
waitForMsg()
}, 20000);
});
}
function viewVerify(data) {
var page = "<div class='alert alert-block text-center'> \
<h4>Please Verify Patient At Check-in</h4> \
<br> \
" + data.first + " " + data.last + " | " + data.email + " | " + data.phone + " \
<br> \
<br> \
<span class='btn btn-success' data-verify-contact>Verify</span> \
<span class='btn btn-danger' data-deny-contact>Deny</span> \
</div> \
";
return page;
}
init();
})(this, document);
public function get_checkin_poll()
{
$filepath = 'storage/work/checkin_poll_' . Auth::user()->id;
$last_cycle = File::get($filepath);
// if last cycle was > 40 secs continue
$time_dif = time() - $last_cycle;
Log::time($time_dif);
if ($time_dif < 40) {
Log::stop('');
exit;
}
$thread = uniqid();
while (1) {
Log::cycle($thread);
$user = User::find(Auth::user()->id);
// if last actiiity was > 40 seconds stop
$active_dif = time() - $user->activity_at;
if ($active_dif < 40)
exit;
$contact = Contact::where_account_user_id(Auth::user()->account_user_id)
->where_request(1)
->first();
if ($contact != null)
break;
// save time of last cycle
File::put($filepath, time());
sleep(2);
}
File::put($filepath, '');
return Response::eloquent($contact);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment