Skip to content

Commit b98db88

Browse files
Merge pull request #338 from MasoniteFramework/fix/334
Fix/334
2 parents 922a715 + 0b6d8db commit b98db88

File tree

9 files changed

+62
-24
lines changed

9 files changed

+62
-24
lines changed

app/http/controllers/WelcomeController.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
from src.masonite.view import View
44
from src.masonite.controllers import Controller
5+
from app.jobs.TestJob import TestJob
6+
from src.masonite import Queue
57

68

79
class WelcomeController(Controller):
810
"""Controller For Welcoming The User."""
911

10-
def show(self, view: View):
12+
def show(self, view: View, queue: Queue):
1113
"""Show the welcome page.
1214
1315
Arguments:
@@ -17,4 +19,5 @@ def show(self, view: View):
1719
Returns:
1820
masonite.view.View -- The Masonite view class.
1921
"""
22+
queue.push(TestJob)
2023
return view.render('welcome')

craft

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python
2+
"""Craft Command.
3+
4+
This module is really used for backup only if the masonite CLI cannot import this for you.
5+
This can be used by running "python craft". This module is not ran when the CLI can
6+
successfully import commands for you.
7+
"""
8+
9+
from cleo import Application
10+
from masonite import __version__
11+
12+
from wsgi import container
13+
14+
application = Application('Masonite Version:', __version__)
15+
16+
for key, value in container.providers.items():
17+
if isinstance(key, str) and key.endswith('Command'):
18+
application.add(container.make('{0}'.format(key)))
19+
20+
if __name__ == '__main__':
21+
application.run()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from orator.migrations import Migration
2+
3+
4+
class CreateQueueJobsTable(Migration):
5+
def up(self):
6+
"""Run the migrations."""
7+
with self.schema.create("queue_jobs") as table:
8+
table.increments("id")
9+
table.string("name")
10+
table.binary("serialized")
11+
table.integer("attempts")
12+
table.integer("failed").nullable()
13+
table.timestamp("ran_at").nullable()
14+
table.timestamp("created_at").nullable()
15+
table.timestamp("wait_until").nullable()
16+
17+
def down(self):
18+
"""Revert the migrations."""
19+
self.schema.drop("queue_jobs")

routes/web.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
ROUTES = [
77
Get().route('/test', None).middleware('auth'),
88
Get('/bad', 'TestController@bad'),
9+
Get('/welcome', 'WelcomeController@show'),
910
Get('/keyerror', 'TestController@keyerror'),
1011
Get().route('/queue', 'TestController@queue'),
1112
Options('options', 'TestController@show'),

src/masonite/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
__title__ = "masonite"
33
__description__ = "The core for the Masonite framework"
44
__url__ = "https://github.com/MasoniteFramework/masonite"
5-
__version__ = "2.3.17"
5+
__version__ = "2.3.18"
66
__author__ = "Joseph Mancuso"
77
__author_email__ = "[email protected]"
88
__licence__ = "MIT"

src/masonite/commands/SeedCommand.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class SeedCommand(Command):
1616
def handle(self):
1717
table = self.argument("table").lower()
1818
subprocess.call(
19-
["orator make:seed {}_table_seeder -p databases/seeds".format(table),],
19+
["orator make:seed {}_table_seeder -p databases/seeds".format(table)],
2020
shell=True,
2121
)
2222

src/masonite/drivers/queue/QueueDatabaseDriver.py

+13-19
Original file line numberDiff line numberDiff line change
@@ -75,30 +75,24 @@ def consume(self, channel, **options): # skipcq
7575
)
7676
schema = schema.connection(channel)
7777
while True:
78-
jobs = schema.table("queue_jobs").where("ran_at", None).get()
78+
builder = schema.table("queue_jobs")
79+
jobs = builder.where_null("ran_at").where(schema.table("queue_jobs").where_null('wait_until').or_where('wait_until', '<=', pendulum.now().to_datetime_string())).limit(1).get()
80+
7981
if not jobs.count():
8082
time.sleep(5)
8183

8284
for job in jobs:
85+
builder.where("id", job["id"]).update(
86+
{
87+
"ran_at": pendulum.now().to_datetime_string(),
88+
}
89+
)
8390
unserialized = pickle.loads(job.serialized)
8491
obj = unserialized["obj"]
8592
args = unserialized["args"]
8693
callback = unserialized["callback"]
8794
ran = job.attempts
8895

89-
wait_time = job["wait_until"]
90-
91-
if not job["wait_until"]:
92-
wait_time = pendulum.now()
93-
else:
94-
if isinstance(wait_time, str):
95-
wait_time = pendulum.parse(job["wait_until"])
96-
else:
97-
wait_time = pendulum.instance(job["wait_until"])
98-
99-
# print(job['wait_until'], wait_time.is_future())
100-
if job["wait_until"] and wait_time.is_future():
101-
continue
10296
try:
10397
try:
10498
if inspect.isclass(obj):
@@ -111,7 +105,7 @@ def consume(self, channel, **options): # skipcq
111105

112106
try:
113107
# attempts = 1
114-
schema.table("queue_jobs").where("id", job["id"]).update(
108+
builder.where("id", job["id"]).update(
115109
{
116110
"ran_at": pendulum.now().to_datetime_string(),
117111
"attempts": job["attempts"] + 1,
@@ -125,7 +119,7 @@ def consume(self, channel, **options): # skipcq
125119

126120
if not obj.run_again_on_fail:
127121
# ch.basic_ack(delivery_tag=method.delivery_tag)
128-
schema.table("queue_jobs").where("id", job["id"]).update(
122+
builder.where("id", job["id"]).update(
129123
{
130124
"ran_at": pendulum.now().to_datetime_string(),
131125
"failed": 1,
@@ -135,12 +129,12 @@ def consume(self, channel, **options): # skipcq
135129

136130
if ran < obj.run_times and isinstance(obj, Queueable):
137131
time.sleep(1)
138-
schema.table("queue_jobs").where("id", job["id"]).update(
139-
{"attempts": job["attempts"] + 1,}
132+
builder.where("id", job["id"]).update(
133+
{"attempts": job["attempts"] + 1}
140134
)
141135
continue
142136
else:
143-
schema.table("queue_jobs").where("id", job["id"]).update(
137+
builder.where("id", job["id"]).update(
144138
{
145139
"attempts": job["attempts"] + 1,
146140
"ran_at": pendulum.now().to_datetime_string(),

src/masonite/providers/UploadProvider.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ def boot(self, manager: UploadManager, view: View):
2424
self.app.bind("Upload", manager.driver(config("storage").DRIVER))
2525
self.app.swap(Upload, manager.driver(config("storage").DRIVER))
2626
view.share(
27-
{"static": static,}
27+
{"static": static}
2828
)

src/masonite/testing/TestCase.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def call(self, method, url, params, wsgi={}):
141141
)
142142

143143
custom_wsgi.update(
144-
{"QUERY_STRING": urlencode(params),}
144+
{"QUERY_STRING": urlencode(params)}
145145
)
146146

147147
self.run_container(custom_wsgi)

0 commit comments

Comments
 (0)