1Gearman::Task(3) User Contributed Perl Documentation Gearman::Task(3)
2
3
4
6 Gearman::Task - a task in Gearman, from the point of view of a client
7
9 my $task = Gearman::Task->new("add", "1+2", {
10 .....
11
12 };
13
14 $taskset->add_task($task);
15 $client->do_task($task);
16 $client->dispatch_background($task);
17
19 Gearman::Task is a Gearman::Client's representation of a task to be
20 done.
21
23 Gearman::Task->new($func, $arg, \%options)
24
25 Creates a new Gearman::Task object, and returns the object.
26
27 $func is the function name to be run. (that you have a worker regis‐
28 tered to process)
29
30 $arg is an opaque scalar or scalarref representing the argument(s) to
31 pass to the distributed function. If you want to pass multiple argu‐
32 ments, you must encode them somehow into this one. That's up to you
33 and your worker.
34
35 %options can contain:
36
37 * uniq
38 A key which indicates to the server that other tasks with the same
39 function name and key will be merged into one. That is, the task
40 will be run just once, but all the listeners waiting on that job
41 will get the response multiplexed back to them.
42
43 Uniq may also contain the magic value "-" (a single hyphen) which
44 means the uniq key is the contents of the args.
45
46 * on_complete
47 A subroutine reference to be invoked when the task is completed.
48 The subroutine will be passed a reference to the return value from
49 the worker process.
50
51 * on_fail
52 A subroutine reference to be invoked when the task fails (or fails
53 for the last time, if retries were specified). No arguments are
54 passed to this callback. This callback won't be called after a
55 failure if more retries are still possible.
56
57 * on_retry
58 A subroutine reference to be invoked when the task fails, but is
59 about to be retried.
60
61 Is passed one argument, what retry attempt number this is. (starts
62 with 1)
63
64 * on_status
65 A subroutine reference to be invoked if the task emits status
66 updates. Arguments passed to the subref are ($numerator, $denomi‐
67 nator), where those are left up to the client and job to determine.
68
69 * retry_count
70 Number of times job will be retried if there are failures.
71 Defaults to 0.
72
73 * high_priority
74 Boolean, whether this job should take priority over other jobs
75 already enqueued.
76
77 * timeout
78 Automatically fail, calling your on_fail callback, after this many
79 seconds have elapsed without an on_fail or on_complete being
80 called. Defaults to 0, which means never. Bypasses any retry_count
81 remaining.
82
83 $task->is_finished
84
85 Returns bool: whether or not task is totally done (on_failure or
86 on_complete callback has been called)
87
88
89
90perl v5.8.8 2007-05-04 Gearman::Task(3)