Skip to content

Commit

Permalink
Added memory usuage check to monit config files for background jobs
Browse files Browse the repository at this point in the history
Added _html fields for article table
Add migration script for changes to article table
  • Loading branch information
sanjeevan committed Jul 12, 2010
1 parent 476f9f2 commit 9a78b18
Show file tree
Hide file tree
Showing 20 changed files with 222 additions and 132 deletions.
3 changes: 1 addition & 2 deletions apps/frontend/modules/article/templates/_article.php
Expand Up @@ -97,8 +97,7 @@
<?php endif; ?>

<?php if ($a->getFlavour() == 'question'): ?>
<?php $question_text = truncate_text($a->getQuestion(), 250); ?>
<div class="question-body"><?php echo myUtil::markdown($question_text); ?></div>
<div class="question-body"><?php echo $a->getQuestionHtml(); ?></div>
<?php endif; ?>

</div>
Expand Down
6 changes: 6 additions & 0 deletions apps/frontend/modules/article/templates/_show_code.php
Expand Up @@ -20,6 +20,12 @@
<div class="clear"></div>
</div>

<div class="summary">
<?php if (strlen($article->getSummary()) > 0): ?>
<?php echo $article->getSummaryHtml(); ?>
<?php endif; ?>
</div>

<pre class="brush: <?php echo $article->getBrushAlias(); ?>">
<?php echo htmlspecialchars($article->getCode()); ?>
</pre>
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/modules/article/templates/_show_link.php
Expand Up @@ -24,7 +24,7 @@

<div class="summary">
<?php if (strlen($article->getSummary()) > 0): ?>
<?php echo myUtil::markdown($article->getSummary()); ?>
<?php echo $article->getSummaryHtml(); ?>
<?php endif; ?>
</div>

Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/modules/article/templates/_show_question.php
Expand Up @@ -20,4 +20,4 @@
<div class="clear"></div>
</div>

<?php echo myUtil::markdown($article->getQuestion()); ?>
<?php echo $article->getQuestionHtml(); ?>
2 changes: 1 addition & 1 deletion apps/frontend/modules/article/templates/_show_snapshot.php
Expand Up @@ -22,6 +22,6 @@

<img class="snapshot" src="<?php echo $snapshot->getUrl(); ?>" />

<p class="snapshot-summary"><?php echo $article->getSummary(); ?></p>
<p class="snapshot-summary"><?php echo $article->getSummaryHtml(); ?></p>

<div class="clear"></div>
2 changes: 1 addition & 1 deletion apps/frontend/modules/invite/templates/_promo.php
@@ -1,6 +1,6 @@
<div id="invite-only">
<span>
<?php echo sfConfig::get('app_name'); ?> is currently invite only, if you want an account then <?php echo link_to('get on our waiting list', 'invite/request')?>
If you want to post new links, code, snapshots or ask a questions then <?php echo link_to('grab an invite here', 'invite/request'); ?>
</span>
<span style="float: right;"><a href="#" onclick="$.get('<?php echo url_for('invite/hidePromo'); ?>'); $('div#invite-only').hide(); return false; ">close</a></span>

Expand Down
16 changes: 16 additions & 0 deletions batch/update-article-html.php
@@ -0,0 +1,16 @@
<?php

require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php');
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'dev', true);
sfContext::createInstance($configuration);

$articles = Doctrine::getTable('Article')->findAll();

foreach ($articles as $article){
$article->setSummaryHtml(myUtil::markdown($article->getSummary()));
$article->setQuestionHtml(myUtil::markdown($article->getQuestion()));
$article->setFulldescriptionHtml(myUtil::markdown($article->getFulldescription()));
$article->save();
}

echo "Updated article html fields \n";
3 changes: 3 additions & 0 deletions config/doctrine/schema.yml
Expand Up @@ -24,6 +24,9 @@ Article:
has_thumbnails: { type: boolean, default: 0 }
flavour: { type: enum, values: [link, code, question, snapshot], default: link}
published: { type: boolean, default: 0 }
summary_html: string
fulldescription_html: string
question_html: string
relations:
User:
local: user_id
Expand Down
1 change: 1 addition & 0 deletions jobs/cache-update.monitrc 100644 → 100755
@@ -1,3 +1,4 @@
check process cache_update1 with pidfile /var/www/codelovely/jobs/run/cache-update-worker1.pid
start = "/var/www/codelovely/jobs/cache-update.php start worker1"
stop = "/var/www/codelovely/jobs/cache-update.php stop worker1"
if totalmemory > 300 MB then restart
1 change: 1 addition & 0 deletions jobs/send-email.monitrc 100644 → 100755
@@ -1,3 +1,4 @@
check process send_send1 with pidfile /var/www/codelovely/jobs/run/send-email-worker1.pid
start = "/var/www/codelovely/jobs/send-email.php start worker1"
stop = "/var/www/codelovely/jobs/send-email.php stop worker1"
if totalmemory > 150 MB then restart
1 change: 1 addition & 0 deletions jobs/thumbnails-scraper.monitrc 100644 → 100755
@@ -1,3 +1,4 @@
check process thumbnails_scraper1 with pidfile /var/www/codelovely/jobs/run/thumbnails-scraper-worker1.pid
start = "/var/www/codelovely/jobs/thumbnails-scraper.php start worker1"
stop = "/var/www/codelovely/jobs/thumbnails-scraper.php stop worker1"
if totalmemory > 200 MB then restart
113 changes: 61 additions & 52 deletions lib/filter/doctrine/base/BaseArticleFormFilter.class.php
Expand Up @@ -13,43 +13,49 @@ abstract class BaseArticleFormFilter extends BaseFormFilterDoctrine
public function setup()
{
$this->setWidgets(array(
'user_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('User'), 'add_empty' => true)),
'thing_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Thing'), 'add_empty' => true)),
'username' => new sfWidgetFormFilterInput(),
'title' => new sfWidgetFormFilterInput(),
'url' => new sfWidgetFormFilterInput(),
'summary' => new sfWidgetFormFilterInput(),
'fulldescription' => new sfWidgetFormFilterInput(),
'code' => new sfWidgetFormFilterInput(),
'code_language' => new sfWidgetFormFilterInput(),
'question' => new sfWidgetFormFilterInput(),
'total_comments' => new sfWidgetFormFilterInput(),
'has_thumbnails' => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
'flavour' => new sfWidgetFormChoice(array('choices' => array('' => '', 'link' => 'link', 'code' => 'code', 'question' => 'question', 'snapshot' => 'snapshot'))),
'published' => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
'created_at' => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
'updated_at' => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
'slug' => new sfWidgetFormFilterInput(),
'user_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('User'), 'add_empty' => true)),
'thing_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Thing'), 'add_empty' => true)),
'username' => new sfWidgetFormFilterInput(),
'title' => new sfWidgetFormFilterInput(),
'url' => new sfWidgetFormFilterInput(),
'summary' => new sfWidgetFormFilterInput(),
'fulldescription' => new sfWidgetFormFilterInput(),
'code' => new sfWidgetFormFilterInput(),
'code_language' => new sfWidgetFormFilterInput(),
'question' => new sfWidgetFormFilterInput(),
'total_comments' => new sfWidgetFormFilterInput(),
'has_thumbnails' => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
'flavour' => new sfWidgetFormChoice(array('choices' => array('' => '', 'link' => 'link', 'code' => 'code', 'question' => 'question', 'snapshot' => 'snapshot'))),
'published' => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
'summary_html' => new sfWidgetFormFilterInput(),
'fulldescription_html' => new sfWidgetFormFilterInput(),
'question_html' => new sfWidgetFormFilterInput(),
'created_at' => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
'updated_at' => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
'slug' => new sfWidgetFormFilterInput(),
));

$this->setValidators(array(
'user_id' => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('User'), 'column' => 'id')),
'thing_id' => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Thing'), 'column' => 'id')),
'username' => new sfValidatorPass(array('required' => false)),
'title' => new sfValidatorPass(array('required' => false)),
'url' => new sfValidatorPass(array('required' => false)),
'summary' => new sfValidatorPass(array('required' => false)),
'fulldescription' => new sfValidatorPass(array('required' => false)),
'code' => new sfValidatorPass(array('required' => false)),
'code_language' => new sfValidatorPass(array('required' => false)),
'question' => new sfValidatorPass(array('required' => false)),
'total_comments' => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
'has_thumbnails' => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
'flavour' => new sfValidatorChoice(array('required' => false, 'choices' => array('link' => 'link', 'code' => 'code', 'question' => 'question', 'snapshot' => 'snapshot'))),
'published' => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
'created_at' => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
'updated_at' => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
'slug' => new sfValidatorPass(array('required' => false)),
'user_id' => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('User'), 'column' => 'id')),
'thing_id' => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Thing'), 'column' => 'id')),
'username' => new sfValidatorPass(array('required' => false)),
'title' => new sfValidatorPass(array('required' => false)),
'url' => new sfValidatorPass(array('required' => false)),
'summary' => new sfValidatorPass(array('required' => false)),
'fulldescription' => new sfValidatorPass(array('required' => false)),
'code' => new sfValidatorPass(array('required' => false)),
'code_language' => new sfValidatorPass(array('required' => false)),
'question' => new sfValidatorPass(array('required' => false)),
'total_comments' => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
'has_thumbnails' => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
'flavour' => new sfValidatorChoice(array('required' => false, 'choices' => array('link' => 'link', 'code' => 'code', 'question' => 'question', 'snapshot' => 'snapshot'))),
'published' => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
'summary_html' => new sfValidatorPass(array('required' => false)),
'fulldescription_html' => new sfValidatorPass(array('required' => false)),
'question_html' => new sfValidatorPass(array('required' => false)),
'created_at' => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
'updated_at' => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
'slug' => new sfValidatorPass(array('required' => false)),
));

$this->widgetSchema->setNameFormat('article_filters[%s]');
Expand All @@ -69,24 +75,27 @@ public function getModelName()
public function getFields()
{
return array(
'id' => 'Number',
'user_id' => 'ForeignKey',
'thing_id' => 'ForeignKey',
'username' => 'Text',
'title' => 'Text',
'url' => 'Text',
'summary' => 'Text',
'fulldescription' => 'Text',
'code' => 'Text',
'code_language' => 'Text',
'question' => 'Text',
'total_comments' => 'Number',
'has_thumbnails' => 'Boolean',
'flavour' => 'Enum',
'published' => 'Boolean',
'created_at' => 'Date',
'updated_at' => 'Date',
'slug' => 'Text',
'id' => 'Number',
'user_id' => 'ForeignKey',
'thing_id' => 'ForeignKey',
'username' => 'Text',
'title' => 'Text',
'url' => 'Text',
'summary' => 'Text',
'fulldescription' => 'Text',
'code' => 'Text',
'code_language' => 'Text',
'question' => 'Text',
'total_comments' => 'Number',
'has_thumbnails' => 'Boolean',
'flavour' => 'Enum',
'published' => 'Boolean',
'summary_html' => 'Text',
'fulldescription_html' => 'Text',
'question_html' => 'Text',
'created_at' => 'Date',
'updated_at' => 'Date',
'slug' => 'Text',
);
}
}
1 change: 1 addition & 0 deletions lib/form/ArticleCodeForm.class.php
Expand Up @@ -81,6 +81,7 @@ public function save(User $user = null, $article = null)

if (strlen($this->getValue('summary')) > 0){
$article->setSummary($this->getValue('summary'));
$article->setSummaryHtml(myUtil::markdown($this->getValue('summary')));
}

$article->setTitle($this->getValue('title'));
Expand Down
1 change: 1 addition & 0 deletions lib/form/ArticleLinkForm.class.php
Expand Up @@ -74,6 +74,7 @@ public function save(User $user = null, $article = null)

if (strlen($this->getValue('summary')) > 0){
$article->setSummary($this->getValue('summary'));
$article->setSummaryHtml(myUtil::markdown($this->getValue('summary')));
}

$article->setFlavour('link');
Expand Down
1 change: 1 addition & 0 deletions lib/form/ArticleQuestionForm.class.php
Expand Up @@ -47,6 +47,7 @@ public function save(User $user, $article = null)
$article->setUsername($user->getUsername());
$article->setTitle($this->getValue('title'));
$article->setQuestion($this->getValue('question'));
$article->setQuestionHtml(myUtil::markdown($this->getValue('question')));
$article->setFlavour('question');
$article->setHasThumbnails(false);
$article->save();
Expand Down
1 change: 1 addition & 0 deletions lib/form/ArticleSnapshotForm.class.php
Expand Up @@ -101,6 +101,7 @@ public function save(User $user = null, $article = null)

if (strlen($this->getValue('summary')) > 0){
$article->setSummary($this->getValue('summary'));
$article->setSummaryHtml(myUtil::markdown($this->getValue('summary')));
}
$article->save();

Expand Down

0 comments on commit 9a78b18

Please sign in to comment.