如何设计执行繁重任务并在前端显示结果的应用(例如Google Search Console) [英] How to design an app that does heavy tasks and show the result in the frontend (ex Google Search Console)

查看:130
本文介绍了如何设计执行繁重任务并在前端显示结果的应用(例如Google Search Console)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们想象一下:

  1. 我必须从URL下载XML文档;
  2. 我必须详细说明该文档并将其信息保存在数据库中,从而创建或更新许多实体.

我认为最好的方法是使用队列.或者也许我也可以使用cronjobs.

I think the best way is to use queues. Or maybe I can also use cronjobs.

我的问题是:如果我使用同一个应用程序执行繁重的任务,并向最终用户显示这些繁重任务的结果,那么繁重的任务可能会降低主网站的速度.

My problem is this: if I use the same app to do the heavy tasks and also to show to the end user the results of those heavy tasks, it may happen that the heavy tasks slow down the main website.

从现实生活中举一个更具体的例子:Google Search Console(或其他执行繁重任务并向最终用户显示结果的应用程序).

Take a more concrete example from real life: Google Search Console (or whatever other app that does heavy tasks and shows results to the end user).

Google Search Console获取XML映射,然后开始下载每个网页,在每个网页上执行大量分析,然后将结果保存到数据库中,以便最终用户可以看到其网站的错误和其他有用信息.

Google Search Console gets the XML map, then starts downloading each webpage, on each webpage performs a lot of analysis, then saves the results to a database and so the end user can see the errors of his website and other useful information.

因此,假设我想再次将Google Search Console作为Symfony应用构建,有哪些可能的方法?

So, put as hypothesis I want to build again Google Search Console as a Symfony app, which are the possible approaches?

我认为我必须使用队列,但是下载网页的应用程序和处理这些网页的应用程序以及显示这些操作结果的公共前端是相同的应用程序,或者是两个或三个独立的应用程序?

I think that for sure I have to use queues, but the app that downloads the webpages and the app that processes these webpages and the public frontend that shows the result of these operations are the same app or are two or three separate apps?

也就是说,我是否要创建一个能够完成所有这些操作的独特应用程序,或者我要创建一个用于下载网页的应用程序,一个要处理这些网页的应用程序,另一个要向用户显示结果的应用程序?

That is, have I to create a unique application that does all these things, or I create an app to download webpages, one other to process these webpages and one other to show to the user the results?

我对此进行了很多思考,但是我找不到适合的设计.

I'm thinking a lot at this, and I'm not able to find a good design to follow.

因为我的直截了当是为每个任务创建多个应用程序以使工作正常进行,但似乎创建多个Symfony应用程序不是一个好选择:

Because my istinct is to create multiple apps for each of those tasks to make the workings but it seems that create multiple Symfony apps isn't a good choice: Symfony 2 multiple apps?

所以我真的不知道该走哪条路:多个应用程序还是一个大型应用程序?如果我使用一个大应用程序,应该使用cronjobs还是使用队列?

So I really don't know which path to follow: multiple apps or one big app? And if I use one big app, should have I to use cronjobs or I have anyway use queues?

推荐答案

  1. 我将首先详细介绍体系结构:

  1. 您可以执行服务,如:
  1. You can do an Service like this :

namespace SomeBundle\Utils;

use SomeBundle\Entity\MyEntity;
use SomeBundle\myException;

class SomeService 
{
  private $var;

  public function __construct()
  {

  }

  public function doStuff()
  {
    // Do stuff
  }
}

要调试服务,可以从 testController 基本控制器调用它.

To debug you service, you can call it from a testController or basic Controller.

  1. 您可以像一样执行命令:
  1. You can make Command like this :

namespace SomeBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

use SomeBundle\Utils\SomeService;

class SomeCommand extends ContainerAwareCommand 
{
  protected function configure()
  {
    $this->setName('some:command')
         ->setDescription('My awesome command');
  }

  protected function execute(InputInterface $input, OutputInterface $output)
  {
    $container = $this->getContainer();
    $sevice = new SomeService($container);
    $results = $service->doStuff();
  }
}

  1. 您可以执行命令应用程序,例如:
  1. You can do an Command Application like this :

require __DIR__.'/vendor/autoload.php';
require_once __DIR__.'/app/AppKernel.php';

$kernel = new AppKernel('dev', true);

use SomeBundle\Command\SomeCommand;
use Symfony\Bundle\FrameworkBundle\Console\Application;

$application = new Application($kernel);
$application->add(new SomeCommand());
$application->run();

希望这会有所帮助!

这篇关于如何设计执行繁重任务并在前端显示结果的应用(例如Google Search Console)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆