Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --oldest and --clear features to prioritize #851

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions prioritize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,33 @@ local function boost(job_matchers, opts)
end
end

local function boost_oldest(job_matchers, opts)
local quiet = opts.quiet
local count = opts.oldest_count
local job = df.global.world.jobs.list
while ( job.next ) do
Comment on lines +206 to +207
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider

for _,job in utils.listpairs(df.global.world.jobs.list) do

job here is link.item, and it takes care of the initial nil for you so you don't have to check for nil

job = job.next
if (job.item and not job.item.flags.do_now and job.item.order_id == -1) then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this excludes manager orders. should it also exclude repeat jobs? what about jobs that already have a worker attached and are in progress?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it probably should preclude repeat jobs, i don't use those in my forts except very rarely so it did not come up for me

the others are also good ideas

job.item.flags.do_now = true
count = count - 1
if (count <= 0) then
return true
end
end
end
end

local function clear_all(job_matchers, opts)
local quiet = opts.quiet
local job = df.global.world.jobs.list
while ( job.next ) do
job = job.next
if (job.item and job.item.flags.do_now) then
job.item.flags.do_now = false
end
end
end

local function print_add_message(job_type, annotation)
annotation = annotation or ''
print(('Automatically prioritizing future jobs of type: %s%s')
Expand Down Expand Up @@ -479,6 +506,13 @@ end
local function parse_commandline(args)
local opts, action, unit_labors, reaction_names = {}, status, nil, nil
local positionals = argparse.processArgsGetopt(args, {
{'o', 'oldest', hasArg=true, handler=function(arg)
action = boost_oldest
opts.oldest_count = arg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest using argparse.nonnegativeInt() to validate arg

end},
{'z', 'clear', handler=function(arg)
action = clear_all
end},
{'a', 'add', handler=function() action = boost_and_watch end},
{'d', 'delete', handler=function() action = remove_watch end},
{'h', 'help', handler=function() opts.help = true end},
Expand Down