Boolean code in PHP / Laravel with job queuing system

I am creating a web scraper using Laravel 3 and have a queue system resque.

Question: Where should I put the logic scrambling code?

  • In the working / working class?

  • In a library class that is statically set by the employee / job class?

  • In the controller function and is the working class / work class of the controller function running?

I am currently using it as a controller function, so I can verify it by going to its URL. It also allows you to perform recurring tasks using Cron, as it resquedoes not allow you to perform recurring tasks. I still need to keep this simple way to test the functions of the scrapers.

Try: . What am I thinking about, how will you organize your code for such purposes?

Working class

class ScraperWorker
{
    public function perform()
    {
        $url = $this->args['url']
        Scraper::do_scrape($url);
    }
}

Scraping class

class Scraper
{
    public static function do_scrape($url) {
        //some scraping code
    }
}   

Controller class

For quick testing and for Cron jobs, click

class Scraper_Controller extends Base_Controller {

    public function test_scrape($url) {
        Scraper::do_scrape($url);
    }
}
+5
source share
1 answer

I think you're on the right track. One thing you could change is to make the Scraper and its methods NOT static. This would make it harder to use, but LOT is easier than unit test. This becomes especially important later when the Scraper becomes more complex and needs to be set up.

PS. PHP-Spider: /. . . , . : .

0

All Articles