Skip to content

Instantly share code, notes, and snippets.

@tsucchi
Created November 9, 2017 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsucchi/eee4f18e254634c53a485f8b15f066e4 to your computer and use it in GitHub Desktop.
Save tsucchi/eee4f18e254634c53a485f8b15f066e4 to your computer and use it in GitHub Desktop.
sub _try {
my ($self, $id, $options) = @_;
my @binds = (
$options->{id},
$options->{queues} || ['default'],
[keys %{$self->minion->tasks}]
);
return $self->pg->db->query(
"update minion_jobs
set started = now()
, state = 'active'
, worker = ?
where id = (
select id from minion_jobs as j
where delayed <= now()
and id = coalesce(?, id)
and (parents = '{}' or not exists (
select 1 from minion_jobs
where id = any (j.parents)
and state in ('inactive', 'active', 'failed')
))
and queue = any (?)
and state = 'inactive'
and task = any (?)
order by priority desc, random_pickup
limit 1
for update skip locked
)
returning id, args, retries, task", $id, @binds
)->expand->hash;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment