php 删除 Laravel 中排队的作业

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20498524/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:14:50  来源:igfitidea点击:

Deleting queued jobs in laravel

phplaravelbeanstalkd

提问by Claire

I have added some jobs to a queue in laravel. However, I forgot to put $job->delete()in the function and there is an error in my function too. This means the job is never ending. It keeps going into it and keeps erroring in my log file. How can I delete it from the command line?

我在 laravel 的队列中添加了一些工作。但是,我忘记$job->delete()输入函数了,我的函数也有错误。这意味着工作永无止境。它不断进入它并在我的日志文件中不断出错。如何从命令行中删除它?

I am using beanstalkf for my queuing.

我正在使用 beanstalkf 进行排队。

回答by DutGRIFF

I am using Redis instead of Beanstalkd but this should be the same in both. Restarting Redis doesn't solve the problem. I looked at RedisQueuesin the Laravel 4.2 API Docsand found:

我使用的是 Redis 而不是 Beanstalkd,但这在两者中应该是相同的。重启Redis并不能解决问题。我查看RedisQueuesLaravel 4.2 API Docs,发现:

public Job|null pop(string $queue = null)
  //Pop the next job off of the queue.

This is the same if you look at BeanstalkedQueue.

如果您查看BeanstalkedQueue.

I threw it in app/routes.phpinside dd*, loaded that page and voila.

我把它app/routes.php放在 dd* 里面,加载了那个页面,瞧。

Route::get('/', function() {
  dd(Queue::pop());
  #return View::make('hello');
});

NOTE:Reload the page once per queue.

注意:每个队列重新加载一次页面。

The queue was pulled off the stack. I would like to see a cleaner solution but this worked for me more than once.

队列被从堆栈中拉出。我想看到一个更干净的解决方案,但这对我来说不止一次。

*dd($var) = Laravel's die and dump function = die(var_dump($var))

*dd($var) = Laravel 的 die 和 dump 函数 = die(var_dump($var))

Edit 1:For Redis

编辑 1:对于 Redis

The above obviously isn't the best solution so here is a better way. Be careful!

以上显然不是最好的解决方案,所以这里有一个更好的方法。当心!

FLUSHDB - Delete all the keys of the currently selected DB. This command never fails.

FLUSHDB - 删除当前选定数据库的所有键。这个命令永远不会失败。

For Redis use FLUSHDB. This will flush the Redis database not Laravel's database. In the terminal:

对于 Redis 使用FLUSHDB。这将刷新 Redis 数据库而不是 Laravel 的数据库。在终端:

$ redis-cli
127.0.0.1:6379> FLUSHDB
OK
127.0.0.1:6379> exit

回答by Jerome Jaglale

Restart Beanstalk. On Ubuntu:

重新启动豆茎。在 Ubuntu 上:

sudo service beanstalkd restart

回答by morrislaptop

I made an artisan command which will clear all the jobs in your queue. You can optionally specify the connection and/or the pipe.

我做了一个工匠命令,它将清除您队列中的所有作业。您可以选择指定连接和/或管道。

https://github.com/morrislaptop/laravel-queue-clear

https://github.com/morrislaptop/laravel-queue-clear

回答by Ahmad Hajjar

Important note: This solution works only for beanstalk

重要说明:此解决方案仅适用于 beanstalk

There are two solutions:

有两种解决方案:

1- From Your PHP Code

1- 从你的 PHP 代码

To delete jobs programatically, you can do this:

要以编程方式删除作业,您可以执行以下操作:

    //Que the job first. (YourJobProcessor is a class that has a method called fire like `fire($job,$data)`
    $res = Queue::later(5, YourJobProcessor::class, $data, 'queue_name');
    //get the job from the que that you just pushed it to
    $job = Queue::getPheanstalk()->useTube("queue_name")->peek($res);
    //get the job from the que that you just pushed it to
    $res = Queue::getPheanstalk()->useTube("queue_name")->delete($job);

If everything went good, the job will not execute, else the job will execute after 5 seconds

如果一切顺利,作业将不会执行,否则作业将在 5 秒后执行

2- From Command Line (Linux and Mac only)

2- 从命令行(仅限 Linux 和 Mac)

From command line (In linux and mac) you can use beanstool.

从命令行(在 linux 和 mac 中),您可以使用 beanstool.

For example, if you want to delete 100 ready jobs from the queue_nametube you can do the following:

例如,如果您想从queue_name管中删除 100 个就绪作业,您可以执行以下操作:

  for i in {1..100}; do beanstool delete -t queue_name --state=ready; done

回答by Claire

Only way I could do it was to restart my computer. Could not find a way to delete a job.

我唯一能做的就是重新启动我的电脑。找不到删除作业的方法。

回答by fideloper

I've used this php-based web admin consolein the past.

我过去使用过这个基于 php 的 web 管理控制台

Otherwise, I believe you'll find yourself using Terminal + telnet, altho I can't find any documentation for deleting via telnet (Just viewing a list of jobs in queue).

否则,我相信您会发现自己在使用终端 + telnet,尽管我找不到任何通过 telnet 删除的文档(只需查看队列中的作业列表)。

It seems that most articles tell you to use your code+library of choice and loop around queues jobsto delete them in this situation.

似乎大多数文章都告诉您在这种情况下使用您选择的代码+库并循环队列作业来删除它们。

回答by cheelahim

Here is Laravel 5.1 compatible command, which allows you to clear Beanstalkd queue. The command takes queue name as argument ('default' by default). Do not forget to register it in app/Console/Kernel.php

这是 Laravel 5.1 兼容命令,它允许您清除 Beanstalkd 队列。该命令将队列名称作为参数(默认为“default”)。不要忘记在 app/Console/Kernel.php 中注册

回答by Guy

For Redis users, instead of flushing, using redis-cli I ran this command:

对于 Redis 用户,我使用 redis-cli 运行以下命令,而不是刷新:

KEYS *queue*

on the Redis instance holding queued jobs, then deleted whatever keys in the response

在持有排队作业的 Redis 实例上,然后删除响应中的任何键

DEL queues:default queues:default:reserved