WWF - 初学者关于 Windows 工作流服务的简单设计决策

发布于 2024-12-19 10:35:37 字数 509 浏览 3 评论 0原文

我想开发一个工作流服务。

我所做的如下:

  1. 我向服务发送图像的 url
  2. 将一条新记录插入到数据库中,并显示 imageABC.jpg 状态:“待处理”
  3. 服务会下载映像并将其保存在文件系统上
  4. 当服务器可以开始处理它更新的映像时, 状态为“开始处理”
  5. 服务对图像进行一些图像处理(时间 消耗)
  6. 服务完成图像处理作业并更新状态 到数据库表中的“完成”,
  7. 服务会发送带有图像 url 的响应问题

: 我希望计算机一次仅对一张图像进行图像处理(我使用共享托管,因此资源有限)

如何确保用户可以调用该服务,并且该服务将执行步骤 1,2,3 (因为这并不是非常耗时)但是会等到上一个图像完成处理吗?

请给我任何建议。我是新人,刚刚学习。 谢谢。

PS:我还想允许客户端通过询问数据库的状态来查看其图像的状态。我可以将其合并到工作流程服务中吗?我应该这样做还是应该将其作为一项单独的服务?

I want to develop a workflow service.

What I do is the following:

  1. I send the service the url to an image
  2. A new record is inserted into the DB saying imageABC.jpg
    status:"pending"
  3. the service downloads the image and saves it on the file system
  4. when the server can begin working on the image it updates the
    status to "begin processing"
  5. the service does some image processing on the image(time
    consuming)
  6. the service finishes the image processing job and updates status
    to "done" in the DB table
  7. the service sends a response with the url to the image

Question:
I want the computer to do the image processing on only one image at a time( I am using shared hosting so resources are limited)

How can I make sure that users can call the service, and the service will do steps 1,2,3 (because this is not extremly time consuming) but than will wait until the previous image has finished processing?

Please give me any advice. I am new and just learning.
Thank you.

PS: I also want to allow the client to see what is the status of it's image by interogating the DB for the status. Can I incorporate this into the workflow service? should I do this or should it be a separate service?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

皓月长歌 2024-12-26 10:35:37

你要么同步做事,要么异步做事。你所描述的对我来说听起来就像是混合物。

单个方法调用可以一次完成所有操作,从而迫使客户端等待一切完成,或者您可以提供客户端可以调用的不同方法来确定状态,例如。

public enum DownloadStatus{
    Pending,
    Processing,
    Done,
}

public class YourService: IYourServiceInterface
{
     public Guid SubmitDownload(string imageUrl)...

     public DownloadStatus GetStatus(Guid downloadId) ...

     public byte[] GetResult(Guid downloadId)...

}

因此,您的客户将向您的服务提交下载。然后,该服务会将 imageUrl 保存在数据库中,状态为 Pending。计划任务(基本上是另一个应用程序)将读取所有待处理任务并开始下载,将每个下载任务标记为正在处理。当计划任务下载并处理图像后,它会将结果保存在某个地方(很可能保存在文件中,如果您坚持的话,也可以保存在数据库中)并将状态设置为“完成”...虽然这一切正在进行时,客户端将通过调用 GetStatus 方法轮询服务的当前状态。轮询间隔应调整为您的作业下载和处理图像所需的预期时间。一旦客户端从 GetStatus 收到 Done 状态,它就知道可以调用 GetResult 并检索图像。

Either you do stuff synchronously or asynchronously. What you are describing sound to me like a mixture.

A single method call can do it all at once, thus forcing the client to wait until everything is done, or you can offer different methods that the client can call to determine the status, such as.

public enum DownloadStatus{
    Pending,
    Processing,
    Done,
}

public class YourService: IYourServiceInterface
{
     public Guid SubmitDownload(string imageUrl)...

     public DownloadStatus GetStatus(Guid downloadId) ...

     public byte[] GetResult(Guid downloadId)...

}

So your client would submit a download to your service. The service will then save the imageUrl in the database as status Pending. A scheduled task (another app basically) will read all pending tasks and begin downloading, marking every download task as Processing. When the scheduled task has downloaded and processed the image it will save the result somewhere (in a file most likely, or in the database if you insist) and set the status to Done... While all this is going, on the client will poll the service for the current status by calling the GetStatus method. The polling interval should be adjusted to the expected time it takes for your job to download and process the image. Once the client receives a Done status from GetStatus it knows that it can call GetResult and retrieve the image.

二手情话 2024-12-26 10:35:37

使用消息队列实现图像处理。当文件上传到服务器然后将其保存到磁盘时,将记录插入数据库并通过将消息插入队列来对文件进行排队以进行处理。然后处理队列中的图像,一次处理一张,完成后更新数据库中的文件状态。

Implement your image processing using a message queue. When file is uploaded to the server then save it to disk, insert a record into the database and queue the file for processing by inserting a message into a queue. Then process the images from the queue, one at a time, and when finished update file status in the database.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文