Gearman::Task(3pm)

πŸ“¦
version 2.004.015 Β· 5 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute

πŸ’– Gearman::Task πŸ’–

okay bestie, welcome to Gearman::Task β€” it's part of the Perl docs, section 3pm, and it's literally just: a task in Gearman, from the point of view of a client. that's the whole vibe. ✨


🌸 NAME 🌸

Gearman::Task β€” a task in Gearman, from the point of view of a client. no cap, that's the name, that's the job. πŸ’…


✨ SYNOPSIS ✨

my $task = Gearman::Task->new("add", "1+2", {
        ...
});

$taskset->add_task($task);
$client->do_task($task);
$client->dispatch_background($task);

πŸ¦‹ DESCRIPTION πŸ¦‹

Gearman::Task is a Gearman::Client's representation of a task to be done. that's it. that's the girl. she's a task, she's got a client, she's ready. πŸ‘‘


πŸŽ€ USAGE πŸŽ€

πŸ’œ Gearman::Task->new($func, $arg, \%options)

Creates a new Gearman::Task object, and returns the object. main character moment fr fr. 🌟

$func is the function name to be run. (yes, that you have a worker registered to process β€” that part is on you, bestie.)

$arg is an opaque scalar or scalarref representing the argument(s) to pass to the distributed function. wanna pass multiple arguments? you gotta encode them somehow into this one. that's up to you and your worker. lowkey chaotic but that's the deal. πŸ™ˆ

%options can contain:

  • uniq β€” a key which indicates to the server that other tasks with the same function name and key will be merged into one. that is, the task will be run just once, but all the listeners waiting on that job will get the response multiplexed back to them.

uniq may also contain the magic value "-" (a single hyphen) which means the uniq key is the contents of the args. iconic shortcut behavior tbh. ✨

  • on_complete β€” a subroutine reference to be invoked when the task is completed. the subroutine will be passed a reference to the return value from the worker process. πŸŽ‰
  • on_fail β€” a subroutine reference to be invoked when the task fails (or fails for the last time, if retries were specified). the reason could be passed to this callback as an argument. this callback won't be called after a failure if more retries are still possible. πŸ’€
  • on_retry β€” a subroutine reference to be invoked when the task fails, but is about to be retried.

is passed one argument, what retry attempt number this is. (starts with 1) πŸ”

  • on_status β€” a subroutine reference to be invoked if the task emits status updates. arguments passed to the subref are ($numerator, $denominator), where those are left up to the client and job to determine. πŸ“Š
  • on_warning β€” a subroutine reference to be invoked if the task emits status updates. arguments passed to the subref are ($numerator, $denominator), where those are left up to the client and job to determine.
okay so real talk: the manpage literally describes on_warning with the exact same words as on_status. not me making that up, that's just what it says. πŸ™ˆ
  • retry_count β€” number of times job will be retried if there are failures. defaults to 0.
  • high_priority β€” the option high_priority is deprecated. use "priority => high" instead. boolean, whether this job should take priority over other jobs already enqueued.
  • priority β€” valid value:
    • high
    • normal (defaul β€” yes the manpage says "defaul", we're keeping her, she's part of the lore πŸ’…)
    • low
  • timeout β€” automatically fail, calling your on_fail callback, after this many seconds have elapsed without an on_fail or on_complete being called. defaults to 0, which means never. bypasses any retry_count remaining. ⏰
  • try_timeout β€” automatically fail, calling your on_retry callback (or on_fail if out of retries), after this many seconds have elapsed. defaults to 0, which means never. ⏳

and that's the whole page bestie, go forth and dispatch some tasks 🫢

this was perl v5.26.2, dated 2018-08-30 β€” the source is User Contributed Perl Documentation, and the page is Gearman::Task(3pm). slay, bye! πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from