From 1c8d74eb5b304a9fa26f5e69d4ab296471797236 Mon Sep 17 00:00:00 2001 From: Pablo Hoffman Date: Fri, 24 Dec 2010 12:47:59 -0200 Subject: [PATCH] scrapyd: populate SCRAPY_SLOT environment variable with the scrapyd slot number --- scrapyd/environ.py | 1 + scrapyd/tests/test_environ.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/scrapyd/environ.py b/scrapyd/environ.py index bf511a4cf..a41e6abb9 100644 --- a/scrapyd/environ.py +++ b/scrapyd/environ.py @@ -21,6 +21,7 @@ class Environment(object): def get_environment(self, message, slot, eggpath): project = message['_project'] env = self.initenv.copy() + env['SCRAPY_SLOT'] = str(slot) env['SCRAPY_PROJECT'] = project if eggpath: env['SCRAPY_EGGFILE'] = eggpath diff --git a/scrapyd/tests/test_environ.py b/scrapyd/tests/test_environ.py index b7c3d97ef..09cac50ae 100644 --- a/scrapyd/tests/test_environ.py +++ b/scrapyd/tests/test_environ.py @@ -26,6 +26,7 @@ class EggStorageTest(unittest.TestCase): slot = 3 env = self.environ.get_environment(msg, slot, '/path/to/file.egg') self.assertEqual(env['SCRAPY_PROJECT'], 'mybot') + self.assertEqual(env['SCRAPY_SLOT'], '3') self.assert_(env['SCRAPY_SQLITE_DB'].endswith('mybot.db')) self.assert_(env['SCRAPY_LOG_FILE'].endswith('/mybot/myspider/ID.log')) self.assert_(env['SCRAPY_EGGFILE'].endswith('/path/to/file.egg')) @@ -36,6 +37,7 @@ class EggStorageTest(unittest.TestCase): slot = 3 env = self.environ.get_environment(msg, slot, None) self.assertEqual(env['SCRAPY_PROJECT'], 'newbot') + self.assertEqual(env['SCRAPY_SLOT'], '3') self.assert_(env['SCRAPY_SQLITE_DB'].endswith('newbot.db')) self.assert_(env['SCRAPY_LOG_FILE'].endswith('/newbot/myspider/ID.log')) self.assertEqual(env['SCRAPY_SETTINGS_MODULE'], 'newbot.settings')