# Routing queues and queuejob event hooks

**URL:** <https://community.openpbs.org/t/routing-queues-and-queuejob-event-hooks/2851>\
**Category:** Developers\
**Created:** [November 16, 2021, 3:36pm UTC](https://community.openpbs.org/t/routing-queues-and-queuejob-event-hooks/2851 "2021-11-16T15:36:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pepe\_grenoble](https://avatars.discourse-cdn.com/v4/letter/p/51bf81/32.png) [@pepe\_grenoble](https://community.openpbs.org/u/pepe_grenoble)\
**Post date:** [November 16, 2021, 3:36pm UTC](https://community.openpbs.org/t/routing-queues-and-queuejob-event-hooks/2851/1 "2021-11-16T15:36:28Z")

</div>

Hi all,  
We have a default queue in our configuration that routes jobs to several other execution queues according to certain resources, mostly walltime.

The question: is it possible to have openpbs executing the queuejob hooks after the job has moved to the final execution queue?

Right now, the order I observe is: first execute the hooks, then route the job, so all my queuejob hooks see the same default routing queue as all the job’s queue.

Cheers,  
Pepe

---

<div class="post-metadata">

**Author:** ![adarsh](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@adarsh](https://community.openpbs.org/u/adarsh)\
**Post date:** [November 17, 2021, 1:50pm UTC](https://community.openpbs.org/t/routing-queues-and-queuejob-event-hooks/2851/2 "2021-11-17T13:50:00Z")

</div>

Could you please share your hook on this forum (if possible) ? and purspose/goal of this hook.

ROUTE\_QUEUE=str(pbs.event().job.queue)  
if ROUTE\_QUEUE=“shortq”:  
else:

---

<div class="post-metadata">

**Author:** ![pepe\_grenoble](https://avatars.discourse-cdn.com/v4/letter/p/51bf81/32.png) [@pepe\_grenoble](https://community.openpbs.org/u/pepe_grenoble)\
**Post date:** [November 17, 2021, 2:04pm UTC](https://community.openpbs.org/t/routing-queues-and-queuejob-event-hooks/2851/3 "2021-11-17T14:04:54Z")

</div>

Hi Adarsh,

I cannot share the hook… but I will explain better what I’m seeing. I have set the default queue to, let’s say, “queue1”… this one is a routing queue that sends to “queue2” or “queue3”… etc. When users submit a job without specifying the queue with the -q option, my hook will get an empty value in job.queue… if they specify -q queue1, the value will be indeed “queue1” and not any of the destinations.

In another cluster I’m working with (it has pbspro), the job.queue will indeed show “queue2” or “queue3”, etc.

It is like if for openpbs the order after submission is:

- execute queuejob hooks
- route
- execute other hooks

but for pbspro is:

- route
- execute queuejob hooks
- execute other hooks

Is this a know difference between openpbs and pbspro? can the order be changed in openpbs to follow that of pbspro? I really don’t want to code in a hook the logic of the routing queue. Imagine if I add another destination to the routing queue, I would have to modify the hook(s) as well!.

Cheers,  
Pepe

---

<div class="post-metadata">

**Author:** ![theunforgiven](https://avatars.discourse-cdn.com/v4/letter/t/e480ec/32.png) [@theunforgiven](https://community.openpbs.org/u/theunforgiven)\
**Post date:** [November 17, 2021, 2:38pm UTC](https://community.openpbs.org/t/routing-queues-and-queuejob-event-hooks/2851/4 "2021-11-17T14:38:10Z")

</div>

I have noticed the reported behavior as well. And to complete the response mentioned above, the routing queue looks like this:

```auto
create queue entry
set queue entry queue_type = Route
set queue entry route_destinations = default
set queue entry route_destinations += queue1
set queue entry route_destinations += queue2
...

```

Considering a `queuejob` hook:

```auto
# queuejob hook
...
myqueue = pbs.event().job.queue

```

Now, as a user, if I submit a job `qsub -l select=...`, then `myqueue` will be unset. User can always explicitly specify the queue switch (e.g. `-q queue1`) and then it works but the question is when the queue is unspecified.

One could, in principle, set to the default queue:

```auto
...
if myqueue is None:
    myqueue = pbs.server().default_queue
    # myqueue is 'default' at this point

```

In this scenario, `myqueue` takes the value of the `default` queue, and not one of the queues that is should route to (queue1, queue2).

As @pepe_grenoble mentioned, pbspro seems to have a slightly different execution sequence: the queue routing takes place **before** the execution of the queuejob hook. In that case, `myqueue` already comes with the queue that is was routed to. So you could do:

```auto
# queuejob hook
...
myqueue = j.pbs.event().job.queue
if str(myqueue) == 'queue1':
    pass
elif str(myqueue) == 'queue2':
    pass

```

With this hook I am trying to apply different rules based on the queue that the job gets assigned to but I haven’t been able to do so in `openpbs`.

---

<div class="post-metadata">

**Author:** ![wilshire](https://avatars.discourse-cdn.com/v4/letter/w/f6c823/32.png) [@wilshire](https://community.openpbs.org/u/wilshire)\
**Post date:** [November 18, 2021, 6:10pm UTC](https://community.openpbs.org/t/routing-queues-and-queuejob-event-hooks/2851/5 "2021-11-18T18:10:01Z")

</div>

What version of PBSPro do you notice that behaviour in?

At least for 2021.1.1 queuejob hooks are executed before any routing is done from a top level routing queue much like you observed with openpbs.

---

<div class="post-metadata">

**Author:** ![pepe\_grenoble](https://avatars.discourse-cdn.com/v4/letter/p/51bf81/32.png) [@pepe\_grenoble](https://community.openpbs.org/u/pepe_grenoble)\
**Post date:** [November 19, 2021, 9:21am UTC](https://community.openpbs.org/t/routing-queues-and-queuejob-event-hooks/2851/6 "2021-11-19T09:21:59Z")

</div>

PBSPro 2021.1.0

Perhaps is this a new “feature” in 2021.1.1?
