Gearman:仍然没有办法从后台工作人员检索自定义数据吗? [英] Gearman: is there still no way to retrieve custom data from a background worker?

查看:115
本文介绍了Gearman:仍然没有办法从后台工作人员检索自定义数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我知道这个问题:

我想知道的是,Gearman仍然是这种情况吗?我正计划将一批图像URL从PHP Web应用程序发送到gearman worker(也用PHP编写;我们称其为主要工人")进行异步处理.然后,该工作人员将为每个映像向低层工作人员提交单独的任务(通过addTask()),调用runTasks()并等待任务完成,同时侦听异常,累积错误消息并更新总体作业状态.

What I want to know, is it still the case with Gearman? I'm planning on sending a batch of image URLs from a PHP web application to the gearman worker (also written in PHP; let's call it "The Main Worker") for processing asynchronously. This worker will then submit a separate task for each image to lower-tier workers (via addTask()), call runTasks() and wait for the tasks to finish, while listening to exceptions, accumulating error messages and updating the overall job status.

虽然我完全可以使用jobStatus()调用从Main Worker检索总体状态,然后只说返回[false,false,0、0]时已处理所有图像,但我肯定需要能够通知用户某些图像无法从其各自的URL中检索或存储在服务器上.

While I'm perfectly ok with retrieving the overall status from the Main Worker using jobStatus() calls, then just say that all of the images were processed when [false, false, 0, 0] is returned, I definitely need to be able to inform the users that some of the images couldn't be retrieved from their respective URLs or stored on the server.

我想我总是可以将自定义数据存储在内存缓存中,然后从Web应用程序中检索它,但对我来说似乎比较脏" ...

I suppose I could always just store the custom data in memcache, then retrieve it from the web app, but it just seems "dirtier" to me...

我没有尝试得到任何结果,因为从php.net手册中看到的情况来看,即使异常处理也只能在同步提交任务时完成,更不用说自定义数据检索了.我只是希望可能会缺少一些东西. 我没记错,我们使用的是带有libgearman6(v 0.27)和PHP 5.3.10的Ubuntu Server 12.04. Gearman扩展程序的版本是1.0.2.我认为这里的数据库无关紧要,因为我不会在任何一个工作人员中使用它.而且我认为我们现在不使用持久性队列.

I'm not trying to get any result, because from what I've seen in the manual on php.net, even the exception handling can only be done when the task is submitted synchronously, not mentioning the custom data retrieval. I just hoped that there could be something I'm missing. I'm I remember correctly, we're using Ubuntu Server 12.04 with libgearman6 (v 0.27) and PHP 5.3.10. The version of the gearman extension is 1.0.2. I think the database is irrelevant here, as I will not be using it in either of the workers. And I think we're not using persistent queues right now.

推荐答案

由于Gearman不会在任务完成后在内存中保留任何任务信息(只是将其报告给同步任务),因此您将无法可以在您的Web应用程序中检索它,而无需将其存储在第三方位置.为此,我们通常在应用程序中使用简单的Web服务,当任务完成或发生错误时,允许工作人员回调应用程序.这样一来,我们就可以在发生错误的情况下保留业务逻辑,以解决错误所在的问题,并让我们的工作人员变得更加笼统(我们可能需要在许多应用程序中调整图像大小,但是某些应用程序可能需要开始几个取决于首先完成图像调整大小的子任务.

Since gearman won't keep any task information in memory after a task has finished (just report it back for a synchronous task), you won't be able to retrieve it in your web application without storing it in a 3rd party location. We usually use a simple web service in the application for this, letting the worker call back to the application when a task has completed or an error has occured. This allows us to keep the business logic about what we'd like to do when such an error happens in the application where it belongs, and let our workers be more general (we might need image resizing in many apps, but some apps might want to start several sub tasks that depend on the image resizing being done first).

在编写时,您还可以让工作人员直接将任务状态或memcached写入数据库,但是我发现让应用程序本身处理逻辑,而不必进行更改和特殊情况处理.工人工作得更好.它也非常适合于工作程序框架,使您可以保持相同的标准化方式来处理实际工作程序代码中的回调.

As you write, you may also let the worker write directly to the database with the state of the task or to memcached, but I've found that letting the application itself handle the logic instead of having to change and special case the workers work better. It's also well suited for a worker framework letting you keep the same standardized way of handling callback across actual worker code.

这篇关于Gearman:仍然没有办法从后台工作人员检索自定义数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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