如何从Laravel的工作ID获得排队的工作?

时间:2016-10-30 12:42:57

标签: laravel queue laravel-5.2 jobs

有没有办法从Laravel的工作ID中获取排队的工作?将作业添加到队列时,我存储作业ID。稍后在某个时间点(处理队列中的作业有延迟),我想从队列中删除该作业。如果我可以使用作业ID获取队列中的作业,我可以使用delete()方法将其删除。

3 个答案:

答案 0 :(得分:8)

我将这段代码用于laravel 5.5:

package ArrayTest;

import java.util.Scanner;

/**
 * Created by quwi on 02/12/2017.
 */`enter code here`
public class Happyness {
    private static Scanner scanner = new Scanner(System.in);


    public static void main(String[] args) {
//        house();
//        money();
        comparison();


    }

    private static void house() {


        //       getting user input and using the switch statement to see the size
        //       of their house

        System.out.println("Please enter the size of your house ");
        String cap = scanner.next();

        switch (cap) {
            case "small":
                System.out.println("you have a small house it means your poor");
                break;
            case "normal":
                System.out.println("your house normal, it mean your not poor nor rich");
                break;
            case "large":
                System.out.println("your house is big it means your rich");
                break;
            default:
                System.out.println("please choose between: small, normal or large");
                break;
        }
    }


    private static void money() {

        System.out.println("please enter a number");
        int wage = scanner.nextInt();
        if (wage < 1000) {
            System.out.println("your poor");
        } else if (wage >= 1000 && wage < 5000) {
            System.out.println("your not poor, your OK");
        } else if (wage > 5000) {
            System.out.println("your rich, Give me money");
        } else {
            System.out.println("please enter a number nothing else");
        }
    }

    private static void comparison() {


        System.out.println("please enter a number");
        int decision = scanner.nextInt();

        switch (decision) {
            case 1:
                money();
                break;
            case 2:
                house();
                break;
            case 3:
                money();
                house();
                break;

            default:
                System.out.println("Please choose 1, 2 or 3");
        }
    }

}

答案 1 :(得分:0)

这是一个队列,所以你不能选择它,但如果你也在队列之外记录数据,你可以在Queue :: before(){}中查看添加到AppServiceProvider.php以检查存储的id或引用他们离队时和处理前的工作。

我也正在研究这个领域,所以如果我弄清楚这个代码,如果我这样做就会发布。当你在before()中获得一个事件回到这里时,你必须打开它并让Job出来检查。

答案 2 :(得分:0)

你可以简单地使用DB :: table()通过id来搜索特定的作业,因为在调度作业时它会返回作业表的id。

use DB;
class ServiceClass{
    public function deleteJobIfExists($id){
        $jobTable = 'jobs';
        $job = DB::table($jobTable)->find($id);
        return $job ? ($job->delete ? 1 : -1 ) : 0;
}
}