Skip to content

Commit

Permalink
Allow producer to be executed only for a given user
Browse files Browse the repository at this point in the history
  • Loading branch information
fguillot committed Jan 15, 2017
1 parent 99225f5 commit 4ab9ca1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
8 changes: 8 additions & 0 deletions app/models/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ function get_all_users()
->findAll();
}

function get_all_user_ids()
{
return Database::getInstance('db')
->table(TABLE)
->asc('id')
->findAllByColumn('id');
}

function get_user_by_id($user_id)
{
return Database::getInstance('db')
Expand Down
14 changes: 11 additions & 3 deletions producer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,24 @@

$options = getopt('', array(
'limit::',
'user::',
));

$limit = get_cli_option('limit', $options);
$user_id = get_cli_option('user', $options);
$connection = new Pheanstalk(BEANSTALKD_HOST);

foreach (Model\User\get_all_users() as $user) {
foreach (Model\Feed\get_feed_ids_to_refresh($user['id'], $limit) as $feed_id) {
if ($user_id) {
$user_ids = array($user_id);
} else {
$user_ids = Model\User\get_all_user_ids();
}

foreach ($user_ids as $user_id) {
foreach (Model\Feed\get_feed_ids_to_refresh($user_id, $limit) as $feed_id) {
$payload = serialize(array(
'feed_id' => $feed_id,
'user_id' => $user['id'],
'user_id' => $user_id,
));

$connection
Expand Down

0 comments on commit 4ab9ca1

Please sign in to comment.