in code, tech

Auto-refresh for Fever on AppFog

Today, I got asked something about my “Installing Fever on AppFog” tutorial. Fever has an inbuilt module to refresh your RSS feeds periodically but this module doesn’t work on all types of servers and it certainly doesn’t work on AppFog. Shaun, being the good guy that he is, lists out a way to set up a curl command with a cron job to refresh the feeds automatically. Unfortunately, AppFog doesn’t support crontab directly either. So, I got asked if there’s a solution for this. After a little bit of Googling and finding this solution on stackoverflow, I built up a working solution specific to Fever on Appfog. The detail follows –

Building a cron job on AppFog involves you to create an additional app that will poll the Fever Refresh API endpoint using a PHP curl command. The code that you must use is as follows –

<?php
    set_time_limit(0);
    while (true) {
        print "blahn";
        $ch = curl_init("http://fever.nitinkhanna.com/?refresh");
        curl_exec($ch);
        curl_close($ch);
        sleep(900);
    }
?>

 

After you copy this, follow the instructions given on the stackoverflow page I’ve referenced. In short, the steps are –
1. Copy the above code and put it in a file – index.php in a new folder on your computer. Replace the “fever.nitinkhanna.com/?refresh” with your own Refresh Endpoint. To find your Endpoint, open your Fever installation and to into Extras.
2. Run the “af push” command on the directory using your Terminal
3. Deploy from the current directory, give the app a name (I gave it FeverCron)
4. It detects the language to be PHP, but say No to that.
5. Select Standalone when it asks for Application Type
6. Select php when it asks run time.
7. When it asks for php start command, give “php index.php”
8. This is important – when it asks you to select the Infrastructure, select the same one as the one you select for your Fever installation. (I selected AWS US East for both)
9. Your app does not need a deployed URL
10. Select the default memory and instances and say No to binding or creating services to bind with the app
11. Say Yes to saving the configuration. After this, your app will be uploaded and started.

If you want to check your app’s functionality, there are two ways –
1. After every 15 minutes (900 seconds), your app will call the Fever Refresh endpoint, so your Fever installation will automatically refresh. This will show up in the Fever App
2. Alternatively, I’ve added a small debug code to print “blah” every time it runs. After a couple of runs of 15 minute intervals, call a command “af logs FeverCron”. This will show blah printed out a couple of times and will also show errors if there are any.

This has working for me all afternoon, without fail. Since Appfog is really good infrastructure, it doesn’t crash or overload because of such a refresh time.

Special thanks to Leonel on stackoverflow for his helpful answer to an important problem.

  • Felix

    Thank you so much. With your help I´ve got it working. Now I finally can fully switch from google reader 🙂

    • All the best! Always glad to see someone enjoying Fever, it’s a really good RSS reader… 🙂

  • Anurag Chandel

    Thanks Nitin for your wonderful article. I have a question: What do I need to do if I have to run more than one script through this functionality? I mean each script would would be executing at different time intervals?

    • Hey Anurag, I believe that anything inside the PHP tags will be run as such. So that’s where you’d put your script. Perhaps you’d like to tell me what you’re planning to do?

      I’ve been thinking of trying out something like a mail module which emails me every time this script runs. If that succeeds, I can think of using it to mail certain articles to my Kindle app as soon as they appear in Fever…

  • Thanks for another great how-to. I modified the script to print the date/time of the update job.
    (I guess this isn’t the better way to do it but it works)

    print “n Fever updated on: “;
    print strftime(‘%c %z’);

    Which logs this:

    ====> /logs/stdout.log <====
    Fever updated on: Fri Mar 15 13:13:53 2013 +0000
    Fever updated on: Fri Mar 15 13:28:53 2013 +0000
    Fever updated on: Fri Mar 15 13:43:53 2013 +0000

    Also, you script looks a but wrong as the < ? doesn't show at the right place. I had to use

    < ?php

    }

    • @maxaudet:disqus Thanks for the updated script and catching the error. I guess WP ate the tags I put in the beginning… 🙂

  • Pingback: ??????Fever°??? | ????????()

  • FY

    Dear Nitin, do I have to create a new app instance in AppFog? I cannot push this to the instance with Fever installed, can I?

    • Hey, @2877e5036d441f2bd5062968c5674d12:disqus you need to create a new instance. This is because –
      a) Every time Fever will reset or update, any additional code you add to it will be removed.
      b) This will make it easier to monitor the auto update process
      c) You’re allowed 10 free AppFog instances, why not use them? 🙂

    • FY

      Ok, I found the answer to my own question. You don’t need to go to AppFog.com to create another instance. When you issue a “sudo af push fevercron”, it will automatically create a instance by the name “fevercron”. In AppFog, you will see this newly created app in your app mission control.

  • Pingback: ??RSS?????Fever°?????????????????????????? « ??????????()

  • Pingback: ??RSS?????Fever°?????????????????????????? | ??????????()